Skip to main content

## CrateDef

# Trait CrateDef

Source

    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 tool_attrs(&self, attr: &[Symbol]) -> Vec<Attribute> { ... }
        fn all_tool_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§

Source

#### fn def_id(&self) -> DefId

Retrieve the unique identifier for the current definition.

## Provided Methods§

Source

#### fn name(&self) -> Symbol

Return the fully qualified name of the current definition.

See `DefId::name` for more details

Source

#### fn trimmed_name(&self) -> Symbol

Return a trimmed name of this definition.

See `DefId::trimmed_name` for more details

Source

#### fn krate(&self) -> Crate

Return information about the crate where this definition is declared.

This will return the crate number and its name.

Source

#### fn span(&self) -> Span

Return the span of this definition.

Source

#### fn tool_attrs(&self, attr: &[Symbol]) -> Vec<Attribute>

Return registered tool attributes with the given attribute name.

FIXME(jdonszelmann): may panic on non-tool attributes. After more attribute work, non-tool attributes will simply return an empty list.

Single segmented name like `#[clippy]` is specified as `&["clippy".to_string()]`. Multi-segmented name like `#[rustfmt::skip]` is specified as `&["rustfmt".to_string(), "skip".to_string()]`.

Source

#### fn all_tool_attrs(&self) -> Vec<Attribute>

Return all tool attributes of this definition.

## Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

## Implementors§

Source§

### impl CrateDef for AdtDef

Source§

### impl CrateDef for AliasDef

Source§

### impl CrateDef for AssocDef

Source§

### impl CrateDef for BrNamedDef

Source§

### impl CrateDef for ClosureDef

Source§

### impl CrateDef for ConstDef

Source§

### impl CrateDef for CoroutineClosureDef

Source§

### impl CrateDef for CoroutineDef

Source§

### impl CrateDef for CoroutineWitnessDef

Source§

### impl CrateDef for CrateItem

Source§

### impl CrateDef for FieldDef

Source§

### impl CrateDef for FnDef

Source§

### impl CrateDef for ForeignDef

Source§

### impl CrateDef for ForeignModuleDef

Source§

### impl CrateDef for GenericDef

Source§

### impl CrateDef for ImplDef

Source§

### impl CrateDef for InstanceDef

Source§

### impl CrateDef for IntrinsicDef

Source§

### impl CrateDef for OpaqueDef

Source§

### impl CrateDef for ParamDef

Source§

### impl CrateDef for RegionDef

Source§

### impl CrateDef for StaticDef

Source§

### impl CrateDef for TraitDef