Skip to main content

MetaExt

Trait MetaExt 

Source
pub trait MetaExt {
    // Required methods
    fn is_path(&self) -> bool;
    fn is_list(&self) -> bool;
    fn is_name_value(&self) -> bool;
    fn as_path(&self) -> Option<&Path>;
    fn as_list(&self) -> Option<&MetaList>;
    fn as_name_value(&self) -> Option<&MetaNameValue>;
    fn is(&self, name: &str) -> bool;
    fn get(&self, path: &str) -> Option<Meta>;
    fn nested(&self) -> Option<Vec<Meta>>;
    fn span(&self) -> Span;
}
Expand description

Extension methods for a single syn::Meta.

Provides variant predicates (is_path, is_list, is_name_value), conversions (as_path, as_list, as_name_value), name checking, and dot-path querying into nested meta lists.

§Examples

use zyn::ext::MetaExt;

// Given #[serde(rename = "id", skip)]
assert!(meta.is("serde"));
assert!(meta.is_list());

let rename = meta.get("rename"); // → Some(NameValue meta)
let skip = meta.get("skip");     // → Some(Path meta)

Required Methods§

Source

fn is_path(&self) -> bool

Returns true if this is a Meta::Path (bare path like #[foo]).

Source

fn is_list(&self) -> bool

Returns true if this is a Meta::List (e.g., #[foo(...)]).

Source

fn is_name_value(&self) -> bool

Returns true if this is a Meta::NameValue (e.g., #[foo = expr]).

Source

fn as_path(&self) -> Option<&Path>

Returns the inner syn::Path if this is a Meta::Path.

Source

fn as_list(&self) -> Option<&MetaList>

Returns the inner syn::MetaList if this is a Meta::List.

Source

fn as_name_value(&self) -> Option<&MetaNameValue>

Returns the inner syn::MetaNameValue if this is a Meta::NameValue.

Source

fn is(&self, name: &str) -> bool

Returns true if the meta’s path matches the given name.

Source

fn get(&self, path: &str) -> Option<Meta>

Navigates nested meta using a dot-separated path with optional index access.

§Examples
use zyn::ext::MetaExt;

// Given meta for #[serde(rename = "id", skip)]
let rename = meta.get("rename"); // → Some(NameValue)

// Given meta for #[derive(Clone, Debug)]
let first = meta.get("[0]"); // → Some(Path for Clone)
Source

fn nested(&self) -> Option<Vec<Meta>>

Parses the contents of a Meta::List as a Vec<Meta>. Returns None if this is not a list variant.

§Examples
use zyn::ext::MetaExt;

// Given meta for #[derive(Clone, Debug)]
let items = meta.nested().unwrap();
// items → [Meta::Path(Clone), Meta::Path(Debug)]
Source

fn span(&self) -> Span

Returns the span of this meta item.

Implementations on Foreign Types§

Source§

impl MetaExt for Meta

Source§

fn is_path(&self) -> bool

Source§

fn is_list(&self) -> bool

Source§

fn is_name_value(&self) -> bool

Source§

fn as_path(&self) -> Option<&Path>

Source§

fn as_list(&self) -> Option<&MetaList>

Source§

fn as_name_value(&self) -> Option<&MetaNameValue>

Source§

fn is(&self, name: &str) -> bool

Source§

fn get(&self, path: &str) -> Option<Meta>

Source§

fn nested(&self) -> Option<Vec<Meta>>

Source§

fn span(&self) -> Span

Implementors§