Skip to main content

Segment

Struct Segment 

Source
pub struct Segment(/* private fields */);
Expand description

Path segment

A single component of a SymbolPath. Just a name string. Kind information is managed by SymbolRegistry, not by Segment.

§Invariants

  • Must be a valid Rust identifier, OR
  • Must be a numeric string (for tuple fields like 0, 1)
  • Must be a scope marker (for InSymbol: $param, $var, $field)

Implementations§

Source§

impl Segment

Source

pub fn new(name: impl AsRef<str>) -> Result<Segment, ParseError>

Create a new segment with validation

§Errors
  • ParseError::InvalidIdentifier: Not a valid Rust identifier
Source

pub fn name(&self) -> &str

Get the segment name

Source

pub fn tuple_field(index: usize) -> Segment

Create a tuple field segment (numeric)

§Examples
let seg = Segment::tuple_field(0);
assert_eq!(seg.name(), "0");
Source

pub fn is_tuple_field(&self) -> bool

Check if this is a tuple field (all digits)

Source

pub fn tuple_field_index(&self) -> Option<usize>

Get tuple field index if this is a tuple field

Source

pub fn is_scope_marker(&self) -> bool

Check if this is a scope marker ($param, $var, $field, $body)

Source

pub fn as_var_scope(&self) -> Option<VarScope>

Get the VarScope if this is a scope marker

Source

pub fn param_scope() -> Segment

Parameter scope segment ($param)

Source

pub fn local_scope() -> Segment

Variable scope segment ($var)

Source

pub fn field_scope() -> Segment

Field scope segment ($field)

Source

pub fn body_scope() -> Segment

Body scope segment ($body)

Source

pub fn stmt_scope() -> Segment

Statement scope segment ($stmt)

Source

pub fn expr_scope() -> Segment

Expression scope segment ($expr)

Source

pub fn inherent_impl(self_ty: &str) -> Segment

Inherent impl segment: <impl Type>

Source

pub fn trait_impl(trait_name: &str, self_ty: &str) -> Segment

Trait impl segment: <impl Trait for Type>

Source

pub fn is_impl(&self) -> bool

Check if this is an impl block segment (<impl ...>)

Source

pub fn is_trait_impl(&self) -> bool

Check if this is a trait impl segment (<impl Trait for Type>)

Source

pub fn impl_self_ty(&self) -> Option<&str>

Extract the self type from an impl segment.

  • <impl Type>Some("Type")
  • <impl Trait for Type>Some("Type")
  • non-impl → None
Source

pub fn impl_trait(&self) -> Option<&str>

Extract the trait name from a trait impl segment.

  • <impl Trait for Type>Some("Trait")
  • <impl Type>None
  • non-impl → None
Source

pub fn is_param_scope(&self) -> bool

Check if this is a parameter scope segment ($param)

Source

pub fn is_local_scope(&self) -> bool

Check if this is a local variable scope segment ($var)

Source

pub fn is_field_scope(&self) -> bool

Check if this is a field scope segment ($field)

Source

pub fn is_body_scope(&self) -> bool

Check if this is a body scope segment ($body)

Source

pub fn is_stmt_scope(&self) -> bool

Check if this is a statement scope segment ($stmt)

Source

pub fn is_expr_scope(&self) -> bool

Check if this is an expression scope segment ($expr)

Trait Implementations§

Source§

impl Clone for Segment

Source§

fn clone(&self) -> Segment

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 Debug for Segment

Source§

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

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

impl<'de> Deserialize<'de> for Segment

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Segment, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Segment

Source§

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

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

impl Hash for Segment

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Segment

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Segment

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Segment

Source§

impl StructuralPartialEq for Segment

Auto Trait Implementations§

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> 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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToCompactString for T
where T: Display,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,