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

Method try_remove_name

crates/derive-impl/src/util.rs:552–587  ·  view source on GitHub ↗
(&mut self, item_name: &str)

Source from the content-addressed store, hash-verified

550 }
551
552 fn try_remove_name(&mut self, item_name: &str) -> Result<Option<NestedMeta>> {
553 self.try_meta_mut(|meta| {
554 let nested = match meta {
555 Meta::List(MetaList { nested, .. }) => Ok(nested),
556 other => Err(syn::Error::new(
557 other.span(),
558 format!(
559 "#[{name}(...)] doesn't contain '{item}' to remove",
560 name = other.get_ident().unwrap(),
561 item = item_name
562 ),
563 )),
564 }?;
565
566 let mut found = None;
567 for (i, item) in nested.iter().enumerate() {
568 let ident = if let Some(ident) = item.get_ident() {
569 ident
570 } else {
571 continue;
572 };
573 if *ident != item_name {
574 continue;
575 }
576 if found.is_some() {
577 return Err(syn::Error::new(
578 item.span(),
579 format!("#[py..({item_name}...)] must be unique but found multiple times"),
580 ));
581 }
582 found = Some(i);
583 }
584
585 Ok(found.map(|idx| nested.remove(idx).into_value()))
586 })
587 }
588
589 fn fill_nested_meta<F>(&mut self, name: &str, new_item: F) -> Result<()>
590 where

Callers 1

gen_module_itemMethod · 0.80

Calls 8

newFunction · 0.85
spanMethod · 0.80
into_valueMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
iterMethod · 0.45
mapMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected