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
impl Segment
Sourcepub fn new(name: impl AsRef<str>) -> Result<Segment, ParseError>
pub fn new(name: impl AsRef<str>) -> Result<Segment, ParseError>
Create a new segment with validation
§Errors
ParseError::InvalidIdentifier: Not a valid Rust identifier
Sourcepub fn tuple_field(index: usize) -> Segment
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");Sourcepub fn is_tuple_field(&self) -> bool
pub fn is_tuple_field(&self) -> bool
Check if this is a tuple field (all digits)
Sourcepub fn tuple_field_index(&self) -> Option<usize>
pub fn tuple_field_index(&self) -> Option<usize>
Get tuple field index if this is a tuple field
Sourcepub fn is_scope_marker(&self) -> bool
pub fn is_scope_marker(&self) -> bool
Check if this is a scope marker ($param, $var, $field, $body)
Sourcepub fn as_var_scope(&self) -> Option<VarScope>
pub fn as_var_scope(&self) -> Option<VarScope>
Get the VarScope if this is a scope marker
Sourcepub fn param_scope() -> Segment
pub fn param_scope() -> Segment
Parameter scope segment ($param)
Sourcepub fn local_scope() -> Segment
pub fn local_scope() -> Segment
Variable scope segment ($var)
Sourcepub fn field_scope() -> Segment
pub fn field_scope() -> Segment
Field scope segment ($field)
Sourcepub fn body_scope() -> Segment
pub fn body_scope() -> Segment
Body scope segment ($body)
Sourcepub fn stmt_scope() -> Segment
pub fn stmt_scope() -> Segment
Statement scope segment ($stmt)
Sourcepub fn expr_scope() -> Segment
pub fn expr_scope() -> Segment
Expression scope segment ($expr)
Sourcepub fn inherent_impl(self_ty: &str) -> Segment
pub fn inherent_impl(self_ty: &str) -> Segment
Inherent impl segment: <impl Type>
Sourcepub fn trait_impl(trait_name: &str, self_ty: &str) -> Segment
pub fn trait_impl(trait_name: &str, self_ty: &str) -> Segment
Trait impl segment: <impl Trait for Type>
Sourcepub fn is_trait_impl(&self) -> bool
pub fn is_trait_impl(&self) -> bool
Check if this is a trait impl segment (<impl Trait for Type>)
Sourcepub fn impl_self_ty(&self) -> Option<&str>
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
Sourcepub fn impl_trait(&self) -> Option<&str>
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
Sourcepub fn is_param_scope(&self) -> bool
pub fn is_param_scope(&self) -> bool
Check if this is a parameter scope segment ($param)
Sourcepub fn is_local_scope(&self) -> bool
pub fn is_local_scope(&self) -> bool
Check if this is a local variable scope segment ($var)
Sourcepub fn is_field_scope(&self) -> bool
pub fn is_field_scope(&self) -> bool
Check if this is a field scope segment ($field)
Sourcepub fn is_body_scope(&self) -> bool
pub fn is_body_scope(&self) -> bool
Check if this is a body scope segment ($body)
Sourcepub fn is_stmt_scope(&self) -> bool
pub fn is_stmt_scope(&self) -> bool
Check if this is a statement scope segment ($stmt)
Sourcepub fn is_expr_scope(&self) -> bool
pub fn is_expr_scope(&self) -> bool
Check if this is an expression scope segment ($expr)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Segment
impl<'de> Deserialize<'de> for Segment
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Segment, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Segment, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Segment
impl Serialize for Segment
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for Segment
impl StructuralPartialEq for Segment
Auto Trait Implementations§
impl Freeze for Segment
impl RefUnwindSafe for Segment
impl Send for Segment
impl Sync for Segment
impl Unpin for Segment
impl UnsafeUnpin for Segment
impl UnwindSafe for Segment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more