From d76dc925a2ce65109f2bf87ce9a07e53dd7670f6 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Fri, 16 Aug 2024 17:59:17 -0700 Subject: [PATCH] Fix 'Env::raw()' doc example comments. Resolves #118. --- src/providers/env.rs | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/providers/env.rs b/src/providers/env.rs index 4ab8ac6..dd78fab 100644 --- a/src/providers/env.rs +++ b/src/providers/env.rs @@ -238,30 +238,54 @@ impl Env { /// considered. /// /// ```rust + /// # use std::collections::BTreeMap; + /// # use figment::util::map; /// use figment::{Jail, providers::Env}; /// /// Jail::expect_with(|jail| { /// jail.set_env("FOO_FOO", 100); /// jail.set_env("BAR_FOO", "hi"); - /// jail.set_env("foobar", "hi"); + /// jail.set_env("foo_bar", "hey"); /// /// // This is like `prefixed("foo_")` without the filtering. - /// let env = Env::raw().map(|k| match k.starts_with("foo_") { - /// true => k["foo_".len()..].into(), - /// false => k.into() + /// let env = Env::raw() + /// .map(|k| match k.starts_with("foo_") { + /// true => k["foo_".len()..].into(), + /// false => k.into() + /// }); + /// + /// // We now have `FOO=100`, `BAR_FOO=hi`, and `bar=hey`. + /// # /* Don't actually do this as it'll include lots of other values. + /// let values = env.iter().collect::>(); + /// # */ + /// # let values = env.iter() + /// # .filter(|(k, _)| k.starts_with("foo") || k.starts_with("bar")) + /// # .collect::>(); + /// assert_eq!(values, map! { + /// "FOO".into() => "100".into(), + /// "BAR_FOO".into() => "hi".into(), + /// "bar".into() => "hey".into(), /// }); /// - /// // We now have `FOO=100`, `BAR_FOO=hi`, and `bar=hi`. - /// assert_eq!(env.clone().filter(|k| k == "foo").iter().count(), 1); - /// /// // Mappings chain, like iterator adapters. /// let env = env.map(|k| match k.starts_with("bar_") { /// true => k["bar_".len()..].into(), /// false => k.into() /// }); /// - /// // We now have `FOO=100`, `FOO=hi`, and `bar=hi`. - /// assert_eq!(env.filter(|k| k == "foo").iter().count(), 2); + /// // We now have `FOO=100`, `FOO=hi`, and `bar=hey`. + /// # /* Don't actually do this as it'll include lots of other values. + /// let values = env.iter().collect::>(); + /// # */ + /// # let values = env.iter() + /// # .filter(|(k, _)| k.starts_with("foo") || k.starts_with("bar")) + /// # .collect::>(); + /// assert_eq!(values, map! { + /// "FOO".into() => "100".into(), + /// "FOO".into() => "hi".into(), + /// "bar".into() => "hey".into(), + /// }); + /// /// Ok(()) /// }); /// ```