pub struct TypeReference { /* private fields */ }Expand description
Unified type reference representing any path/type usage in Rust code.
Implementations§
Source§impl TypeReference
impl TypeReference
Sourcepub fn new<I, S>(segments: I) -> Self
pub fn new<I, S>(segments: I) -> Self
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.
Sourcepub const fn with_crate_prefix(self) -> Self
pub const fn with_crate_prefix(self) -> Self
Sets crate:: prefix.
Sourcepub const fn with_self_prefix(self) -> Self
pub const fn with_self_prefix(self) -> Self
Sets self:: prefix.
Sourcepub const fn with_super(self, levels: usize) -> Self
pub const fn with_super(self, levels: usize) -> Self
Sets super:: prefix with given level count.
Sourcepub fn with_alias(self, alias: impl Into<String>) -> Self
pub fn with_alias(self, alias: impl Into<String>) -> Self
Sets an alias (as Name).
Sourcepub fn with_group(self, items: Vec<GroupItem>) -> Self
pub fn with_group(self, items: Vec<GroupItem>) -> Self
Sets grouped items ({A, B, C}).
Sourcepub const fn prefix(&self) -> PathPrefix
pub const fn prefix(&self) -> PathPrefix
Returns the path prefix.
Sourcepub const fn is_relative(&self) -> bool
pub const fn is_relative(&self) -> bool
Returns true if this is a relative path (self::, super::, crate::).
Sourcepub fn is_from_crate(&self, crate_name: &str) -> bool
pub fn is_from_crate(&self, crate_name: &str) -> bool
Checks if this path is from a specific crate.
Sourcepub fn final_name(&self) -> Option<&str>
pub fn final_name(&self) -> Option<&str>
Returns the final name (last segment or alias if present).
Sourcepub fn truncate_to_depth(&self, depth: usize) -> Self
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");Sourcepub fn to_path_string(&self) -> String
pub fn to_path_string(&self) -> String
Converts to string representation.
Trait Implementations§
Source§impl Clone for TypeReference
impl Clone for TypeReference
Source§fn clone(&self) -> TypeReference
fn clone(&self) -> TypeReference
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more