MCPcopy Index your code
hub / github.com/RustPython/RustPython / from_nested

Method from_nested

crates/derive-impl/src/util.rs:121–155  ·  view source on GitHub ↗
(
        item_ident: Ident,
        meta_ident: Ident,
        nested: I,
        allowed_names: &[&'static str],
    )

Source from the content-addressed store, hash-verified

119
120impl ItemMetaInner {
121 pub fn from_nested<I>(
122 item_ident: Ident,
123 meta_ident: Ident,
124 nested: I,
125 allowed_names: &[&'static str],
126 ) -> Result<Self>
127 where
128 I: core::iter::Iterator<Item = NestedMeta>,
129 {
130 let (meta_map, lits) = nested.into_unique_map_and_lits(|path| {
131 if let Some(ident) = path.get_ident() {
132 let name = ident.to_string();
133 if allowed_names.contains(&name.as_str()) {
134 Ok(Some(name))
135 } else {
136 Err(err_span!(
137 ident,
138 "#[{meta_ident}({name})] is not one of allowed attributes [{}]",
139 allowed_names.iter().format(", ")
140 ))
141 }
142 } else {
143 Ok(None)
144 }
145 })?;
146 if !lits.is_empty() {
147 bail_span!(meta_ident, "#[{meta_ident}(..)] cannot contain literal")
148 }
149
150 Ok(Self {
151 item_ident,
152 meta_ident,
153 meta_map,
154 })
155 }
156
157 pub fn item_name(&self) -> String {
158 self.item_ident.to_string()

Callers

nothing calls this directly

Calls 6

to_stringMethod · 0.80
SomeClass · 0.50
ErrClass · 0.50
containsMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected