Struct crate_inspector::Crate

source ·
pub struct Crate(/* private fields */);

Implementations§

source§

impl Crate

source

pub fn all_items(&self) -> impl Iterator<Item = &Item>

All items in the crate, including external items referenced locally.

source

pub fn items(&self) -> impl Iterator<Item = &Item>

Items in the crate, excluding external items referenced locally.

Examples found in repository?
examples/downcast.rs (line 9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    use crate_inspector::{CrateBuilder, StructItem};

    let builder = CrateBuilder::default()
        .toolchain("nightly")
        .manifest_path("Cargo.toml");
    let krate = builder.build().unwrap();

    for item in krate.items() {
        if let Some(strc) = krate.downcast::<StructItem>(item) {
            println!("struct: {}", strc.name());
        }
    }
}
More examples
Hide additional examples
examples/items.rs (line 9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    use crate_inspector::CrateBuilder;

    let builder = CrateBuilder::default()
        .toolchain("nightly")
        .manifest_path("Cargo.toml");
    let krate = builder.build().unwrap();

    for item in krate.items() {
        println!("item: {:?}", item.name);
    }
    for strc in krate.structs() {
        println!("struct: {}", strc.name());
        println!("#impls: {}", strc.impls().count());
    }
    for enm in krate.enums() {
        println!("enum: {}", enm.name());
        println!("variants: {:?}", enm.variants().collect::<Vec<_>>());
        println!(
            "#methods: {}",
            enm.impls().fold(0, |acc, i| acc + i.functions().count())
        );
    }
    for sub in krate.sub_modules() {
        println!("submodule: {}", sub.name());
    }
    if let Some(item) = krate.get_item("format") {
        println!("item: {:?}", item.id);
    }
}
source

pub fn krate(&self) -> &Crate

source

pub fn item_summary(&self) -> impl Iterator<Item = &ItemSummary>

source

pub fn downcast<'a, T: CrateItem<'a> + 'a>( &'a self, item: &'a Item ) -> Option<T>

Downcast an item to a specific type T: CrateItem.

Examples found in repository?
examples/downcast.rs (line 10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    use crate_inspector::{CrateBuilder, StructItem};

    let builder = CrateBuilder::default()
        .toolchain("nightly")
        .manifest_path("Cargo.toml");
    let krate = builder.build().unwrap();

    for item in krate.items() {
        if let Some(strc) = krate.downcast::<StructItem>(item) {
            println!("struct: {}", strc.name());
        }
    }
}
source

pub fn all_modules(&self) -> impl Iterator<Item = ModuleItem<'_>>

source

pub fn modules(&self) -> impl Iterator<Item = ModuleItem<'_>>

root module included

source

pub fn sub_modules(&self) -> impl Iterator<Item = ModuleItem<'_>>

root module not included

submodules of submodules not included

Examples found in repository?
examples/items.rs (line 24)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    use crate_inspector::CrateBuilder;

    let builder = CrateBuilder::default()
        .toolchain("nightly")
        .manifest_path("Cargo.toml");
    let krate = builder.build().unwrap();

    for item in krate.items() {
        println!("item: {:?}", item.name);
    }
    for strc in krate.structs() {
        println!("struct: {}", strc.name());
        println!("#impls: {}", strc.impls().count());
    }
    for enm in krate.enums() {
        println!("enum: {}", enm.name());
        println!("variants: {:?}", enm.variants().collect::<Vec<_>>());
        println!(
            "#methods: {}",
            enm.impls().fold(0, |acc, i| acc + i.functions().count())
        );
    }
    for sub in krate.sub_modules() {
        println!("submodule: {}", sub.name());
    }
    if let Some(item) = krate.get_item("format") {
        println!("item: {:?}", item.id);
    }
}
source

pub fn all_functions(&self) -> impl Iterator<Item = FunctionItem<'_>>

Enumerates all functions including submodules. methods & associated functions & function declarations included

source

pub fn functions(&self) -> impl Iterator<Item = FunctionItem<'_>>

Enumerates root module functions. methods & associated functions & function declarations not included

source

pub fn all_constants(&self) -> impl Iterator<Item = ConstantItem<'_>>

Enumerates all constants including submodules

source

pub fn constants(&self) -> impl Iterator<Item = ConstantItem<'_>>

Enumerates root module constants

source

pub fn all_statics(&self) -> impl Iterator<Item = StaticItem<'_>>

Enumerates all statics including submodules

source

pub fn statics(&self) -> impl Iterator<Item = StaticItem<'_>>

Enumerates root module statics

source

pub fn all_structs(&self) -> impl Iterator<Item = StructItem<'_>>

Enumerates all structs including submodules

source

pub fn structs(&self) -> impl Iterator<Item = StructItem<'_>>

Enumerates root module structs

Examples found in repository?
examples/items.rs (line 12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    use crate_inspector::CrateBuilder;

    let builder = CrateBuilder::default()
        .toolchain("nightly")
        .manifest_path("Cargo.toml");
    let krate = builder.build().unwrap();

    for item in krate.items() {
        println!("item: {:?}", item.name);
    }
    for strc in krate.structs() {
        println!("struct: {}", strc.name());
        println!("#impls: {}", strc.impls().count());
    }
    for enm in krate.enums() {
        println!("enum: {}", enm.name());
        println!("variants: {:?}", enm.variants().collect::<Vec<_>>());
        println!(
            "#methods: {}",
            enm.impls().fold(0, |acc, i| acc + i.functions().count())
        );
    }
    for sub in krate.sub_modules() {
        println!("submodule: {}", sub.name());
    }
    if let Some(item) = krate.get_item("format") {
        println!("item: {:?}", item.id);
    }
}
source

pub fn all_traits(&self) -> impl Iterator<Item = TraitItem<'_>>

Enumerates all traits including submodules

source

pub fn traits(&self) -> impl Iterator<Item = TraitItem<'_>>

Enumerates root module traits

source

pub fn all_enums(&self) -> impl Iterator<Item = EnumItem<'_>>

Enumerates all enums including submodules

source

pub fn enums(&self) -> impl Iterator<Item = EnumItem<'_>>

Enumerates root module enums

Examples found in repository?
examples/items.rs (line 16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    use crate_inspector::CrateBuilder;

    let builder = CrateBuilder::default()
        .toolchain("nightly")
        .manifest_path("Cargo.toml");
    let krate = builder.build().unwrap();

    for item in krate.items() {
        println!("item: {:?}", item.name);
    }
    for strc in krate.structs() {
        println!("struct: {}", strc.name());
        println!("#impls: {}", strc.impls().count());
    }
    for enm in krate.enums() {
        println!("enum: {}", enm.name());
        println!("variants: {:?}", enm.variants().collect::<Vec<_>>());
        println!(
            "#methods: {}",
            enm.impls().fold(0, |acc, i| acc + i.functions().count())
        );
    }
    for sub in krate.sub_modules() {
        println!("submodule: {}", sub.name());
    }
    if let Some(item) = krate.get_item("format") {
        println!("item: {:?}", item.id);
    }
}
source

pub fn all_type_aliases(&self) -> impl Iterator<Item = TypeAliasItem<'_>>

source

pub fn type_aliases(&self) -> impl Iterator<Item = TypeAliasItem<'_>>

source

pub fn all_trait_aliases(&self) -> impl Iterator<Item = TraitAliasItem<'_>>

source

pub fn trait_aliases(&self) -> impl Iterator<Item = TraitAliasItem<'_>>

source

pub fn all_opaque_tys(&self) -> impl Iterator<Item = OpaqueTyItem<'_>>

source

pub fn opaque_tys(&self) -> impl Iterator<Item = OpaqueTyItem<'_>>

source

pub fn all_unions(&self) -> impl Iterator<Item = UnionItem<'_>>

source

pub fn unions(&self) -> impl Iterator<Item = UnionItem<'_>>

source

pub fn all_impls(&self) -> impl Iterator<Item = ImplItem<'_>>

Enumerates all referenced impls including submodules, std

source

pub fn impls(&self) -> impl Iterator<Item = ImplItem<'_>>

Enumerates root module impls

source

pub fn all_macros(&self) -> impl Iterator<Item = MacroItem<'_>>

Enumerates all macros including submodules

source

pub fn macros(&self) -> impl Iterator<Item = MacroItem<'_>>

Enumerates root module macros

source

pub fn all_imports(&self) -> impl Iterator<Item = ImportItem<'_>>

Enumerates all imports including submodules

source

pub fn imports(&self) -> impl Iterator<Item = ImportItem<'_>>

Enumerates root module imports

source

pub fn get_item(&self, name: &str) -> Option<&Item>

Get an item by its name.

Examples found in repository?
examples/items.rs (line 27)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    use crate_inspector::CrateBuilder;

    let builder = CrateBuilder::default()
        .toolchain("nightly")
        .manifest_path("Cargo.toml");
    let krate = builder.build().unwrap();

    for item in krate.items() {
        println!("item: {:?}", item.name);
    }
    for strc in krate.structs() {
        println!("struct: {}", strc.name());
        println!("#impls: {}", strc.impls().count());
    }
    for enm in krate.enums() {
        println!("enum: {}", enm.name());
        println!("variants: {:?}", enm.variants().collect::<Vec<_>>());
        println!(
            "#methods: {}",
            enm.impls().fold(0, |acc, i| acc + i.functions().count())
        );
    }
    for sub in krate.sub_modules() {
        println!("submodule: {}", sub.name());
    }
    if let Some(item) = krate.get_item("format") {
        println!("item: {:?}", item.id);
    }
}
source

pub fn get_constant(&self, name: &str) -> Option<ConstantItem<'_>>

Get a constant by its name.

source

pub fn get_function(&self, name: &str) -> Option<FunctionItem<'_>>

Get a function by its name.

source

pub fn get_struct(&self, name: &str) -> Option<StructItem<'_>>

Get a struct by its name.

source

pub fn get_enum(&self, name: &str) -> Option<EnumItem<'_>>

Get an enum by its name.

source

pub fn get_trait(&self, name: &str) -> Option<TraitItem<'_>>

Get a trait by its name.

source

pub fn get_type_alias(&self, name: &str) -> Option<TypeAliasItem<'_>>

Get a type alias by its name.

source

pub fn get_trait_alias(&self, name: &str) -> Option<TraitAliasItem<'_>>

Get a trait alias by its name.

source

pub fn get_opaque_ty(&self, name: &str) -> Option<OpaqueTyItem<'_>>

Get an opaque type by its name.

source

pub fn get_union(&self, name: &str) -> Option<UnionItem<'_>>

Get a union by its name.

source

pub fn get_module(&self, name: &str) -> Option<ModuleItem<'_>>

Get a module by its name.

Trait Implementations§

source§

impl Clone for Crate

source§

fn clone(&self) -> Crate

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Crate

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for Crate

§

type Target = Crate

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl PartialEq for Crate

source§

fn eq(&self, other: &Crate) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Crate

source§

impl StructuralEq for Crate

source§

impl StructuralPartialEq for Crate

Auto Trait Implementations§

§

impl RefUnwindSafe for Crate

§

impl Send for Crate

§

impl Sync for Crate

§

impl Unpin for Crate

§

impl UnwindSafe for Crate

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.