pub fn parse(cfg: &MetaItem) -> Result<Cfg, InvalidCfgError> {
        let name = cfg.name();
        match cfg.node {
            MetaItemKind::Word => Ok(Cfg::Cfg(name, None)),
            MetaItemKind::NameValue(ref lit) => match lit.node {
                LitKind::Str(value, _) => Ok(Cfg::Cfg(name, Some(value))),
                _ => Err(InvalidCfgError {
                    // FIXME: if the main #[cfg] syntax decided to support non-string literals,
                    // this should be changed as well.
                    msg: "value of cfg option should be a string literal",
                    span: lit.span,
                }),
            },
            MetaItemKind::List(ref items) => {
                let mut sub_cfgs = items.iter().map(Cfg::parse_nested);
                match &*name.as_str() {
                    "all" => sub_cfgs.fold(Ok(Cfg::True), |x, y| Ok(x? & y?)),
                    "any" => sub_cfgs.fold(Ok(Cfg::False), |x, y| Ok(x? | y?)),
                    "not" => if sub_cfgs.len() == 1 {
                        Ok(!sub_cfgs.next().unwrap()?)
                    } else {
                        Err(InvalidCfgError {
                            msg: "expected 1 cfg-pattern",
                            span: cfg.span,
                        })
                    },
                    _ => Err(InvalidCfgError {
                        msg: "invalid predicate",
                        span: cfg.span,
                    }),
                }
            }
        }
    }
/// Parses a `MetaItem` into a `Cfg`.
///
/// The `MetaItem` should be the content of the `#[cfg(...)]`, e.g., `unix` or
/// `target_os = "redox"`.
///
/// If the content is not properly formatted, it will return an error indicating what and where
/// the error is.
Parses a `MetaItem` into a `Cfg`.

If the content is not properly formatted, it will return an error indicating what and where
the error is.
Parses a ` MetaItem ` into a ` Cfg ` . If the content is not properly formatted it will return an error indicating what and where the error is .
pub fn parse(cfg: &MetaItem) -> Result<Cfg, InvalidCfgError> {
        let name = cfg.name();
        match cfg.node {
            MetaItemKind::Word => Ok(Cfg::Cfg(name, None)),
            MetaItemKind::NameValue(ref lit) => match lit.node {
                LitKind::Str(value, _) => Ok(Cfg::Cfg(name, Some(value))),
                _ => Err(InvalidCfgError {
                    // FIXME: if the main #[cfg] syntax decided to support non-string literals,
                    // this should be changed as well.
                    msg: "value of cfg option should be a string literal",
                    span: lit.span,
                }),
            },
            MetaItemKind::List(ref items) => {
                let mut sub_cfgs = items.iter().map(Cfg::parse_nested);
                match &*name.as_str() {
                    "all" => sub_cfgs.fold(Ok(Cfg::True), |x, y| Ok(x? & y?)),
                    "any" => sub_cfgs.fold(Ok(Cfg::False), |x, y| Ok(x? | y?)),
                    "not" => if sub_cfgs.len() == 1 {
                        Ok(!sub_cfgs.next().unwrap()?)
                    } else {
                        Err(InvalidCfgError {
                            msg: "expected 1 cfg-pattern",
                            span: cfg.span,
                        })
                    },
                    _ => Err(InvalidCfgError {
                        msg: "invalid predicate",
                        span: cfg.span,
                    }),
                }
            }
        }
    }
pub fn parse ( cfg : & MetaItem ) -> Result < Cfg , InvalidCfgError > { let name = cfg . name ( ) ; match cfg . node { MetaItemKind :: Word => Ok ( Cfg :: Cfg ( name , None ) ) , MetaItemKind :: NameValue ( ref lit ) => match lit . node { LitKind :: Str ( value , _ ) => Ok ( Cfg :: Cfg ( name , Some ( value ) ) ) , _ => Err ( InvalidCfgError { // FIXME: if the main #[cfg] syntax decided to support non-string literals, // this should be changed as well. msg : " " , span : lit . span , } ) , } , MetaItemKind :: List ( ref items ) => { let mut sub_cfgs = items . iter ( ) . map ( Cfg :: parse_nested ) ; match & * name . as_str ( ) { " " => sub_cfgs . fold ( Ok ( Cfg :: True ) , | x , y | Ok ( x ? & y ? ) ) , " " => sub_cfgs . fold ( Ok ( Cfg :: False ) , | x , y | Ok ( x ? | y ? ) ) , " " => if sub_cfgs . len ( ) == 1 { Ok ( ! sub_cfgs . next ( ) . unwrap ( ) ? ) } else { Err ( InvalidCfgError { msg : " " , span : cfg . span , } ) } , _ => Err ( InvalidCfgError { msg : " " , span : cfg . span , } ) , } } } }
Parses a `MetaItem` into a `Cfg`.
Parses a ` MetaItem ` into a ` Cfg ` .
cfg
&MetaItem
cfg
&MetaItem