Skip to main content

codama_attributes/codama_directives/
skip_directive.rs

1use crate::{Attribute, CodamaAttribute, CodamaDirective};
2use codama_errors::CodamaError;
3use codama_syn_helpers::Meta;
4
5#[derive(Debug, PartialEq)]
6pub struct SkipDirective;
7
8impl SkipDirective {
9    pub fn parse(meta: &Meta) -> syn::Result<Self> {
10        meta.assert_directive("skip")?;
11        Ok(Self)
12    }
13}
14
15impl<'a> TryFrom<&'a CodamaAttribute<'a>> for &'a SkipDirective {
16    type Error = CodamaError;
17
18    fn try_from(attribute: &'a CodamaAttribute) -> Result<Self, Self::Error> {
19        match attribute.directive.as_ref() {
20            CodamaDirective::Skip(ref a) => Ok(a),
21            _ => Err(CodamaError::InvalidCodamaDirective {
22                expected: "skip".to_string(),
23                actual: attribute.directive.name().to_string(),
24            }),
25        }
26    }
27}
28
29impl<'a> TryFrom<&'a Attribute<'a>> for &'a SkipDirective {
30    type Error = CodamaError;
31
32    fn try_from(attribute: &'a Attribute) -> Result<Self, Self::Error> {
33        <&CodamaAttribute>::try_from(attribute)?.try_into()
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn ok() {
43        let meta: Meta = syn::parse_quote! { skip };
44        let directive = SkipDirective::parse(&meta).unwrap();
45        assert_eq!(directive, SkipDirective);
46    }
47}