Skip to main content

PathSegment

Struct PathSegment 

Source
pub struct PathSegment<Kind = AnyKind> { /* private fields */ }
Expand description

A typed path segment: one “piece” of a Rust path, with extra structure.

§What does that mean?

In Rust, every item (function, type, trait, field…) has a path starting at its crate root. For example, in a crate called my_crate:

mod a {
    mod b {
        fn hello() {}
    }
    trait Foo {
        fn f() {
            enum T {
                C { field: u8 },
            }
        }
    }
}

Some paths and their segments are:

PathSegments
my_crate[my_crate]
my_crate::a[my_crate], [a]
my_crate::a::b::hello[my_crate], [a], [b], [hello]
my_crate::a::Foo[my_crate], [a], [Foo]
my_crate::a::Foo::f[my_crate], [a], [Foo::f]
my_crate::a::Foo::f::T[my_crate], [a], [Foo::f], [T]
my_crate::a::Foo::f::T::C[my_crate], [a], [Foo::f], [T::C]
my_crate::a::Foo::f::T::C::field[my_crate], [a], [Foo::f], [T::C::field]

Each [X] here is a path segment.

§Hierarchy

Path segments form a hierarchy: each one knows its parent. For example, the field my_field is inside the constructor of MyVariant, which is inside the enum MyEnum, which lives inside the function f, and so on – all the way up to the crate root.

This parenthood is important:

  • a field segment always has a constructor parent (e.g. my_field → MyVariant).
  • an associated item always has a trait/impl container parent (e.g. f → Foo).
  • everything ultimately has a crate as its top parent.

§Why does this matter?

This strong typing of segments lets tools:

  • disambiguate names across contexts (e.g. two types with the same constructor name),
  • generate unique, human-readable names in other languages/backends,
  • walk up the chain of parents to reconstruct full paths.

For example, with the F* backend, constructors are not namespaced under the name of their type, but live directly at top-level. Thus, they need to be unique. Using the hierarchy, we can print them as Foo_MyVariant instead of Foo.MyVariant.

Implementations§

Source§

impl<K> PathSegment<K>

Source

pub fn payload(&self) -> PathSegmentPayload

Returns the payload of this path segment (named vs. unnamed and why).

Source

pub fn disambiguator(&self) -> u32

Returns the rustc path disambiguator for this segment.

Source

pub fn kind(&self) -> &K

Returns the kind of this segment as an [K].

Source§

impl PathSegment<ConstructorKind>

Source

pub fn lift(&self) -> PathSegment<AnyKind>

Lift a PathSegment of kind ConstructorKind to a PathSegment of kind AnyKind.

Source§

impl PathSegment<TypeDefKind>

Source

pub fn lift(&self) -> PathSegment<AnyKind>

Lift a PathSegment of kind TypeDefKind to a PathSegment of kind AnyKind.

Source§

impl PathSegment<AssocItemContainerKind>

Source

pub fn lift(&self) -> PathSegment<AnyKind>

Lift a PathSegment of kind AssocItemContainerKind to a PathSegment of kind AnyKind.

Source§

impl PathSegment

Source

pub fn parent(&self) -> Option<PathSegment>

Returns the parent path segment, if any.

Parents exist only for:

All other kinds return None.

Source

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

Returns an iterator over self and all its ancestors, walking up via Self::parent until no parent remains.

Trait Implementations§

Source§

impl<Kind: Clone> Clone for PathSegment<Kind>

Source§

fn clone(&self) -> PathSegment<Kind>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Kind: Debug> Debug for PathSegment<Kind>

Source§

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

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

impl PartialEq for PathSegment

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<Kind> Freeze for PathSegment<Kind>
where Kind: Freeze,

§

impl<Kind> RefUnwindSafe for PathSegment<Kind>
where Kind: RefUnwindSafe,

§

impl<Kind> Send for PathSegment<Kind>
where Kind: Send,

§

impl<Kind> Sync for PathSegment<Kind>
where Kind: Sync,

§

impl<Kind> Unpin for PathSegment<Kind>
where Kind: Unpin,

§

impl<Kind> UnsafeUnpin for PathSegment<Kind>
where Kind: UnsafeUnpin,

§

impl<Kind> UnwindSafe for PathSegment<Kind>
where Kind: UnwindSafe,

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
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IsBody for T
where T: Clone + 'static,

Source§

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

Source§

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>,

Source§

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>,

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more