pub struct NixConfig { /* private fields */ }
Expand description
A newtype wrapper around a [HashMap
], where the key is the name of the Nix
setting, and the value is the value of that setting. If the setting accepts
a list of values, the value will be space delimited.
Implementations§
Source§impl NixConfig
impl NixConfig
pub fn new() -> Self
pub fn settings(&self) -> &IndexMap<String, String>
pub fn settings_mut(&mut self) -> &mut IndexMap<String, String>
pub fn into_settings(self) -> IndexMap<String, String>
Sourcepub fn parse_file(path: &Path) -> Result<Self, ParseError>
pub fn parse_file(path: &Path) -> Result<Self, ParseError>
Attempt to parse the nix.conf
at the provided path.
std::fs::write(
"nix.conf",
b"experimental-features = flakes nix-command\nwarn-dirty = false\n",
)?;
let nix_conf = nix_config_parser::NixConfig::parse_file(&std::path::Path::new("nix.conf"))?;
assert_eq!(
nix_conf.settings().get("experimental-features").unwrap(),
"flakes nix-command"
);
assert_eq!(nix_conf.settings().get("warn-dirty").unwrap(), "false");
std::fs::remove_file("nix.conf")?;
Sourcepub fn parse_string(
contents: String,
origin: Option<&Path>,
) -> Result<Self, ParseError>
pub fn parse_string( contents: String, origin: Option<&Path>, ) -> Result<Self, ParseError>
Attempt to parse the nix.conf
out of the provided String
. The origin
parameter is Option
al, and only influences potential error messages.
let nix_conf_string = String::from("experimental-features = flakes nix-command");
let nix_conf = nix_config_parser::NixConfig::parse_string(nix_conf_string, None)?;
assert_eq!(
nix_conf.settings().get("experimental-features").unwrap(),
"flakes nix-command"
);
Trait Implementations§
impl Eq for NixConfig
impl StructuralPartialEq for NixConfig
Auto Trait Implementations§
impl Freeze for NixConfig
impl RefUnwindSafe for NixConfig
impl Send for NixConfig
impl Sync for NixConfig
impl Unpin for NixConfig
impl UnwindSafe for NixConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.