# konst.rs - source
Source of the Rust file `/home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-macros-backend-0.13.2/src/konst.rs`.
Keywords: rust, rustlang, rust-lang

     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

    use crate::pyfunction::parse_name_attribute;
    use syn::ext::IdentExt;

    #[derive(Clone, PartialEq, Debug)]
    pub struct ConstSpec {
        pub is_class_attr: bool,
        pub python_name: syn::Ident,
    }

    impl ConstSpec {
        // For now, the only valid attribute is `#[classattr]`.
        pub fn parse(name: &syn::Ident, attrs: &mut Vec<syn::Attribute>) -> syn::Result<ConstSpec> {
            let mut new_attrs = Vec::new();
            let mut is_class_attr = false;

            for attr in attrs.iter() {
                if let syn::Meta::Path(name) = attr.parse_meta()? {
                    if name.is_ident("classattr") {
                        is_class_attr = true;
                        continue;
                    }
                }
                new_attrs.push(attr.clone());
            }

            attrs.clear();
            attrs.extend(new_attrs);

            Ok(ConstSpec {
                is_class_attr,
                python_name: parse_name_attribute(attrs)?.unwrap_or_else(|| name.unraw()),
            })
        }
    }