about summary refs log tree commit diff
path: root/pkgs/profpatsch/nman/nman.rs
blob: 16bd62712269853f5d2fc6ef73caa54fc066c0a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#[derive(Debug)]
enum DrvOutput<'a> {
    Out,
    Bin,
    Lib,
    Man,
    Dev,
    DevDoc,
    DevMan,
    Other(&'a [u8]),
}

#[derive(Debug)]
struct DrvWithOutput<'a> {
    drv_path: &'a [u8],
    output: DrvOutput<'a>,
}

fn parse_drv_path<'a>(path: &'a [u8]) -> Option<DrvWithOutput<'a>> {
    let mut split = path.split(|c| char::from(c.to_owned()) == '!');
    split.next().map(|p| DrvWithOutput {
        drv_path: p,
        output: split.next().map(|s| DrvOutput::Other(s))
                            .unwrap_or(DrvOutput::Out),
    }).and_then(|parsed| match split.next() {
        Some(_) => None,
        None => Some(parsed),
    })
}

fn main() -> std::io::Result<()> {
    println!("{:?}", parse_drv_path(b"/nix/store/58i9psln992xjwk8ig1v3l3a4p9sslnp-lowdown-0.7.9.drv"));
    Ok(())
}