diff options
author | sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> | 2021-02-14 21:57:55 +0100 |
---|---|---|
committer | sternenseemann <sternenseemann@systemli.org> | 2021-02-25 19:52:33 +0100 |
commit | 2be83b9b99a31fe46528b5d9a2a915c18ac46434 (patch) | |
tree | 01c2da039bfca8ff3170c6f2ac12568067e01cd7 /pkgs/profpatsch/nman/nman.rs | |
parent | 86f73c53cb9f40bc1fee66d13bf05fe688ed58f8 (diff) |
pkgs/profpatsch/nman: move parse_drv_* into impls
* parse_drv_output → DrvOutput::parse * parse_drv_path → DrvWithOutput::parse
Diffstat (limited to 'pkgs/profpatsch/nman/nman.rs')
-rw-r--r-- | pkgs/profpatsch/nman/nman.rs | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/pkgs/profpatsch/nman/nman.rs b/pkgs/profpatsch/nman/nman.rs index fdbed2eb..0ea99d99 100644 --- a/pkgs/profpatsch/nman/nman.rs +++ b/pkgs/profpatsch/nman/nman.rs @@ -87,6 +87,24 @@ enum DrvOutput<'a> { Other(&'a [u8]), } +impl<'a> DrvOutput<'a> { + /// Convert a string (Nix strings may be arbitrary bytes) + /// into a parsed [`DrvOutput`]. No sanity checking is + /// done, anything strange is pased into [`DrvOutput::Other`]. + fn parse(output: &'a [u8]) -> Self { + match output { + b"out" => DrvOutput::Out, + b"bin" => DrvOutput::Bin, + b"lib" => DrvOutput::Lib, + b"man" => DrvOutput::Man, + b"dev" => DrvOutput::Dev, + b"devdoc" => DrvOutput::DevDoc, + b"devman" => DrvOutput::DevMan, + _ => DrvOutput::Other(output), + } + } +} + /// A derivation represented as a path /// coupled with a parsed [`DrvOutput`] /// for sorting purposes. @@ -109,39 +127,25 @@ impl DrvWithOutput<'_> { } } -/// Convert a string (Nix strings may be arbitrary bytes) -/// into a parsed [`DrvOutput`]. No sanity checking is -/// done, anything strange is pased into [`DrvOutput::Other`]. -fn parse_output<'a>(output: &'a [u8]) -> DrvOutput<'a> { - match output { - b"out" => DrvOutput::Out, - b"bin" => DrvOutput::Bin, - b"lib" => DrvOutput::Lib, - b"man" => DrvOutput::Man, - b"dev" => DrvOutput::Dev, - b"devdoc" => DrvOutput::DevDoc, - b"devman" => DrvOutput::DevMan, - _ => DrvOutput::Other(output), - } -} - -/// Parse a line of the output of `nix-instantiate`, of the form: -/// `/nix/store/<drv file>[!<output>]` into a [`DrvWithOutput`] -/// structure. -fn parse_drv_path<'a>(drv_path: &'a [u8]) -> Option<DrvWithOutput<'a>> { - let mut split = drv_path.split(|c| char::from(*c) == '!'); - let path = split.next().filter(|s| s.len() > 0)?; - let output = split.next() - .map(parse_output) - .unwrap_or(DrvOutput::Out); - - match split.next() { - None => Some(DrvWithOutput { - path: path, - output: output, - rendered: drv_path, - }), - Some(_) => None, +impl<'a> DrvWithOutput<'a> { + /// Parse a line of the output of `nix-instantiate`, of the form: + /// `/nix/store/<drv file>[!<output>]` into a [`DrvWithOutput`] + /// structure. + fn parse(drv_path: &'a [u8]) -> Option<Self> { + let mut split = drv_path.split(|c| char::from(*c) == '!'); + let path = split.next().filter(|s| s.len() > 0)?; + let output = split.next() + .map(DrvOutput::parse) + .unwrap_or(DrvOutput::Out); + + match split.next() { + None => Some(DrvWithOutput { + path: path, + output: output, + rendered: drv_path, + }), + Some(_) => None, + } } } @@ -262,7 +266,7 @@ fn open_man_page<'a>(attr: &'a str, section: Option<&'a str>, page: &'a str) -> let mut drvs: Vec<DrvWithOutput> = inst.stdout.split(|c| char::from(*c) == '\n') - .filter_map(parse_drv_path).collect(); + .filter_map(DrvWithOutput::parse).collect(); if drvs.len() <= 0 { return Err(NmanError::ParseError("nix-instantiate")); |