Skip to main content

TypeReference

Struct TypeReference 

Source
pub struct TypeReference { /* private fields */ }
Expand description

Unified type reference representing any path/type usage in Rust code.

Implementations§

Source§

impl TypeReference

Source

pub fn new<I, S>(segments: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Creates a new TypeReference from path segments with no prefix or suffix.

Use the builder methods (with_crate_prefix, with_alias, with_glob, etc.) to set a prefix or suffix after construction.

Source

pub const fn with_crate_prefix(self) -> Self

Sets crate:: prefix.

Source

pub const fn with_self_prefix(self) -> Self

Sets self:: prefix.

Source

pub const fn with_super(self, levels: usize) -> Self

Sets super:: prefix with given level count.

Source

pub fn with_alias(self, alias: impl Into<String>) -> Self

Sets an alias (as Name).

Source

pub fn with_glob(self) -> Self

Marks as glob import (::*).

Source

pub fn with_group(self, items: Vec<GroupItem>) -> Self

Sets grouped items ({A, B, C}).

Source

pub fn segments(&self) -> &[String]

Returns the path segments.

Source

pub const fn prefix(&self) -> PathPrefix

Returns the path prefix.

Source

pub const fn is_relative(&self) -> bool

Returns true if this is a relative path (self::, super::, crate::).

Source

pub fn is_from_crate(&self, crate_name: &str) -> bool

Checks if this path is from a specific crate.

Source

pub const fn has_glob(&self) -> bool

Returns true if this has a glob.

Source

pub const fn has_group(&self) -> bool

Returns true if this has a group.

Source

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

Returns the final name (last segment or alias if present).

Source

pub fn truncate_to_depth(&self, depth: usize) -> Self

Truncates the path to the given depth (number of segments).

If the path has more segments than depth, the segments are truncated and the suffix is dropped. Otherwise the reference is returned unchanged.

§Examples
use crawk::TypeReference;

// "module::analyzer::Error" (3 segments) truncated to depth 2
// becomes "module::analyzer" (suffix dropped)
let reference = TypeReference::new(["module", "analyzer", "Error"]);
let truncated = reference.truncate_to_depth(2);
assert_eq!(truncated.to_path_string(), "module::analyzer");
Source

pub fn to_path_string(&self) -> String

Converts to string representation.

Trait Implementations§

Source§

impl Clone for TypeReference

Source§

fn clone(&self) -> TypeReference

Returns a duplicate 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 TypeReference

Source§

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

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

impl Display for TypeReference

Source§

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

Formats the full path string, including prefix (crate::, self::, etc.), segments, and suffix (alias, glob, or group).

Source§

impl Hash for TypeReference

Source§

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

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 TypeReference

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Eq for TypeReference

Source§

impl StructuralPartialEq for TypeReference

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