pub struct WorkspaceFilePath { /* private fields */ }Expand description
Normalized relative path from workspace root (self-contained)
§Design
This type holds the relative path, workspace root, and crate name, making it completely self-contained. You can get the absolute path and derive symbol paths without any external context or provider.
relative: Path from workspace_root (used for Hash/Eq/Serialize)workspace_root: Shared workspace root (Arc for lightweight sharing)crate_name: The crate this file belongs to (required)
§Creation
Always create via WorkspacePathResolver. Direct construction
with new_unchecked() is for internal/test use only.
let resolver = WorkspacePathResolver::new("/path/to/workspace".into());
let path = resolver.resolve("src/lib.rs")?;Implementations§
Source§impl WorkspaceFilePath
impl WorkspaceFilePath
Sourcepub fn as_relative(&self) -> &Path
pub fn as_relative(&self) -> &Path
Get the relative path
Sourcepub fn workspace_root(&self) -> &Path
pub fn workspace_root(&self) -> &Path
Get the workspace root
Sourcepub fn crate_name(&self) -> &CrateName
pub fn crate_name(&self) -> &CrateName
Get the crate name
Sourcepub fn to_absolute(&self) -> PathBuf
pub fn to_absolute(&self) -> PathBuf
Get absolute path (no I/O, self-contained)
Sourcepub fn canonicalize(&self) -> Result<PathBuf>
pub fn canonicalize(&self) -> Result<PathBuf>
Get canonicalized absolute path (with I/O)
Sourcepub fn is_rust_file(&self) -> bool
pub fn is_rust_file(&self) -> bool
Check if this is a Rust source file
Sourcepub fn is_binary_entry(&self) -> bool
pub fn is_binary_entry(&self) -> bool
Check if this is a binary entry point (main.rs or src/bin/*.rs)
Binary entry points are handled separately from library code because:
main.rsandlib.rsboth map to the crate root in module path terms- They represent different logical crates (binary vs library)
- Storing them together causes data overwrite issues
§Returns
true if this file is:
src/main.rsor*/src/main.rssrc/bin/*.rsor*/src/bin/*.rs
Sourcepub fn with_context(
&self,
workspace_root: Arc<Path>,
crate_name: CrateName,
) -> Self
pub fn with_context( &self, workspace_root: Arc<Path>, crate_name: CrateName, ) -> Self
Create a new WorkspaceFilePath with different context
This is useful after deserialization when both workspace_root and crate_name need to be set or updated.
Sourcepub fn with_relative(&self, relative: impl Into<PathBuf>) -> Self
pub fn with_relative(&self, relative: impl Into<PathBuf>) -> Self
Create a new WorkspaceFilePath with different relative path
This is useful for creating sibling files (e.g., creating src/storage.rs
when you have src/lib.rs). The workspace_root and crate_name are inherited
from the original path.
§Example
let lib_rs = resolver.resolve("src/lib.rs")?;
let storage_rs = lib_rs.with_relative("src/storage.rs");Sourcepub fn sibling(&self, file_name: &str) -> Self
pub fn sibling(&self, file_name: &str) -> Self
Create a sibling file in the same directory
This is useful for creating module files (e.g., creating src/storage.rs
when you have src/lib.rs).
§Example
let lib_rs = resolver.resolve("src/lib.rs")?;
let storage_rs = lib_rs.sibling("storage.rs");
assert_eq!(storage_rs.as_relative(), Path::new("src/storage.rs"));Sourcepub fn write(&self, content: impl AsRef<[u8]>) -> Result<()>
pub fn write(&self, content: impl AsRef<[u8]>) -> Result<()>
Write content to this file, creating parent directories if needed
This is the preferred way to write files in a workspace context. It automatically creates any missing parent directories before writing.
§Example
let path = resolver.resolve("src/new_module/lib.rs")?;
path.write("// New module\n")?; // Creates src/new_module/ if neededSourcepub fn read_bytes(&self) -> Result<Vec<u8>>
pub fn read_bytes(&self) -> Result<Vec<u8>>
Read content as bytes from this file
Trait Implementations§
Source§impl AsRef<Path> for WorkspaceFilePath
impl AsRef<Path> for WorkspaceFilePath
Source§impl Clone for WorkspaceFilePath
impl Clone for WorkspaceFilePath
Source§fn clone(&self) -> WorkspaceFilePath
fn clone(&self) -> WorkspaceFilePath
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WorkspaceFilePath
impl Debug for WorkspaceFilePath
Source§impl Display for WorkspaceFilePath
impl Display for WorkspaceFilePath
Source§impl Hash for WorkspaceFilePath
impl Hash for WorkspaceFilePath
Source§impl PartialEq for WorkspaceFilePath
impl PartialEq for WorkspaceFilePath
Source§impl Serialize for WorkspaceFilePath
impl Serialize for WorkspaceFilePath
impl Eq for WorkspaceFilePath
Auto Trait Implementations§
impl Freeze for WorkspaceFilePath
impl RefUnwindSafe for WorkspaceFilePath
impl Send for WorkspaceFilePath
impl Sync for WorkspaceFilePath
impl Unpin for WorkspaceFilePath
impl UnsafeUnpin for WorkspaceFilePath
impl UnwindSafe for WorkspaceFilePath
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> 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