pub struct VirtualPath(/* private fields */);Expand description
A path in a virtual file system.
Implementations§
Source§impl VirtualPath
impl VirtualPath
Sourcepub fn virtualize(
root_path: &Path,
path: &Path,
) -> Result<Self, VirtualizeError>
pub fn virtualize( root_path: &Path, path: &Path, ) -> Result<Self, VirtualizeError>
Creates a virtual path from a real path and a real root.
Returns None if the file path is not contained in the root (i.e. if
root_path is not a lexical prefix of path). No file system
operations are performed.
This is the single function that translates from a real path to a
virtual path. Its counterpart is VirtualPath::realize.
Sourcepub fn realize(&self, root: &Path) -> Result<PathBuf, RealizeError>
pub fn realize(&self, root: &Path) -> Result<PathBuf, RealizeError>
Turns the virtual path into an actual file system path (where the
project or package resides). You need to provide the appropriate root
path, relative to which this path will be resolved.
This is the single function that translates from a virtual path to a
real path. Its counterpart is VirtualPath::virtualize.
This function has platform-specific output and returns an error if the
path contains platform-specific syntax that could lexically escape the
root. Currently, no file system operations are performed, though this
may change in the future.
This can be used in the implementations of World::source and
World::file.
Sourcepub fn into_with_slash(self) -> EcoString
pub fn into_with_slash(self) -> EcoString
Extracts the path with a leading slash.
Sourcepub fn get_with_slash(&self) -> &str
pub fn get_with_slash(&self) -> &str
Returns the path with a leading slash.
Sourcepub fn get_without_slash(&self) -> &str
pub fn get_without_slash(&self) -> &str
Returns the path without a leading slash.
Sourcepub fn file_stem(&self) -> Option<&str>
pub fn file_stem(&self) -> Option<&str>
Returns the file name portion of the path without the extension.
Sourcepub fn with_extension(&self, ext: &str) -> Self
pub fn with_extension(&self, ext: &str) -> Self
Returns a modified path with an adjusted extension.
§Panics
Panics if the resulting path segment would be invalid, e.g. because the extension contains a forward or backslash.
Sourcepub fn parent(&self) -> Option<Self>
pub fn parent(&self) -> Option<Self>
Returns the path with its final component removed.
Returns None if the path is already at the root.
Sourcepub fn relative_from(&self, base: &Self) -> EcoString
pub fn relative_from(&self, base: &Self) -> EcoString
Expresses this path as a relative path from the given base path.
Source§impl VirtualPath
impl VirtualPath
Sourcepub fn within_root(path: &Path, root: &Path) -> Option<Self>
👎Deprecated: use virtualize with swapped arguments instead
pub fn within_root(path: &Path, root: &Path) -> Option<Self>
use virtualize with swapped arguments instead
Create a virtual path from a real path and a real root.
Sourcepub fn resolve(&self, root: &Path) -> Option<PathBuf>
👎Deprecated: use realize instead
pub fn resolve(&self, root: &Path) -> Option<PathBuf>
use realize instead
Resolve the virtual path relative to an actual file system root (where the project or package resides).
Sourcepub fn as_rootless_path(&self) -> &Path
👎Deprecated: use get_without_slash instead
pub fn as_rootless_path(&self) -> &Path
use get_without_slash instead
Get the underlying path without a leading / or \.
Sourcepub fn as_rooted_path(&self) -> &Path
👎Deprecated: use get_with_slash instead
pub fn as_rooted_path(&self) -> &Path
use get_with_slash instead
Get the underlying path with a leading / or \.
Trait Implementations§
Source§impl Clone for VirtualPath
impl Clone for VirtualPath
Source§fn clone(&self) -> VirtualPath
fn clone(&self) -> VirtualPath
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 VirtualPath
impl Debug for VirtualPath
impl Eq for VirtualPath
Source§impl Hash for VirtualPath
impl Hash for VirtualPath
Source§impl PartialEq for VirtualPath
impl PartialEq for VirtualPath
Source§fn eq(&self, other: &VirtualPath) -> bool
fn eq(&self, other: &VirtualPath) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for VirtualPath
Auto Trait Implementations§
impl Freeze for VirtualPath
impl RefUnwindSafe for VirtualPath
impl Send for VirtualPath
impl Sync for VirtualPath
impl Unpin for VirtualPath
impl UnsafeUnpin for VirtualPath
impl UnwindSafe for VirtualPath
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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 more