pub trait CrateDef {
// Required method
fn def_id(&self) -> DefId;
// Provided methods
fn name(&self) -> Symbol { ... }
fn trimmed_name(&self) -> Symbol { ... }
fn krate(&self) -> Crate { ... }
fn span(&self) -> Span { ... }
fn attrs_by_path(&self, attr: &[Symbol]) -> Vec<Attribute> { ... }
fn all_attrs(&self) -> Vec<Attribute> { ... }
}
Expand description
A trait for retrieving information about a particular definition.
Implementors must provide the implementation of def_id
which will be used to retrieve
information about a crate’s definition.
Required Methods§
Provided Methods§
Sourcefn trimmed_name(&self) -> Symbol
fn trimmed_name(&self) -> Symbol
Return a trimmed name of this definition.
This can be used to print more user friendly diagnostic messages.
If a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we trim its path and print only the name.
For example, this function may shorten std::vec::Vec
to just Vec
,
as long as there is no other Vec
importable anywhere.
Sourcefn krate(&self) -> Crate
fn krate(&self) -> Crate
Return information about the crate where this definition is declared.
This will return the crate number and its name.
Sourcefn attrs_by_path(&self, attr: &[Symbol]) -> Vec<Attribute>
fn attrs_by_path(&self, attr: &[Symbol]) -> Vec<Attribute>
Return attributes with the given attribute name.
Single segmented name like #[inline]
is specified as &["inline".to_string()]
.
Multi-segmented name like #[rustfmt::skip]
is specified as &["rustfmt".to_string(), "skip".to_string()]
.