Trait proc_macro_roids::FieldExt
source · pub trait FieldExt {
// Required methods
fn type_name(&self) -> &Ident;
fn is_phantom_data(&self) -> bool;
fn contains_tag(&self, namespace: &Path, tag: &Path) -> bool;
fn namespace_parameter(&self, namespace: &Path) -> Option<Meta>;
fn namespace_parameters(&self, namespace: &Path) -> Vec<Meta>;
fn tag_parameter(&self, namespace: &Path, tag: &Path) -> Option<Meta>;
fn tag_parameters(&self, namespace: &Path, tag: &Path) -> Vec<Meta>;
}
Expand description
Functions to make it ergonomic to inspect Field
s and their attributes.
Required Methods§
sourcefn type_name(&self) -> &Ident
fn type_name(&self) -> &Ident
Returns the simple type name of a field.
For example, the PhantomData
in std::marker::PhantomData<T>
.
sourcefn is_phantom_data(&self) -> bool
fn is_phantom_data(&self) -> bool
Returns whether the field is PhantomData
.
Note that the detection is a string comparison instead of a type ID comparison, so is prone to inaccurate detection, for example:
use std::marker::PhantomData as GhostData;
use other_crate::OtherType as PhantomData;
sourcefn contains_tag(&self, namespace: &Path, tag: &Path) -> bool
fn contains_tag(&self, namespace: &Path, tag: &Path) -> bool
Returns whether a field contains a given #[namespace(tag)]
attribute.
Parameters
namespace
: Thepath()
of the first-level attribute.tag
: Thepath()
of the second-level attribute.
sourcefn namespace_parameter(&self, namespace: &Path) -> Option<Meta>
fn namespace_parameter(&self, namespace: &Path) -> Option<Meta>
Returns the parameter from #[namespace(parameter)]
.
Parameters
namespace
: Thepath()
of the first-level attribute.
Panics
Panics if there is more than one parameter for the tag.
sourcefn namespace_parameters(&self, namespace: &Path) -> Vec<Meta>
fn namespace_parameters(&self, namespace: &Path) -> Vec<Meta>
Returns the parameters from #[namespace(param1, param2, ..)]
.
Parameters
namespace
: Thepath()
of the first-level attribute.
sourcefn tag_parameter(&self, namespace: &Path, tag: &Path) -> Option<Meta>
fn tag_parameter(&self, namespace: &Path, tag: &Path) -> Option<Meta>
Returns the parameter from #[namespace(tag(parameter))]
.
Parameters
namespace
: Thepath()
of the first-level attribute.tag
: Thepath()
of the second-level attribute.
Panics
Panics if there is more than one parameter for the tag.
sourcefn tag_parameters(&self, namespace: &Path, tag: &Path) -> Vec<Meta>
fn tag_parameters(&self, namespace: &Path, tag: &Path) -> Vec<Meta>
Returns the parameters from #[namespace(tag(param1, param2, ..))]
.
Parameters
namespace
: Thepath()
of the first-level attribute.tag
: Thepath()
of the second-level attribute.