VirtualPath

Struct VirtualPath 

Source
pub struct VirtualPath<Marker = ()> { /* private fields */ }
Expand description

A user-facing path clamped to the virtual root path.

virtualpath_display() shows a rooted, forward-slashed path (e.g., "/a/b.txt"). Use virtual manipulation methods to compose paths while preserving clamping, and convert to StrictPath with unvirtual() for system-facing I/O.

Implementations§

Source§

impl<Marker> VirtualPath<Marker>

Source

pub fn with_root<P: AsRef<Path>>(root: P) -> Result<Self>

Create the virtual root ("/") for the given filesystem root.

Sugar for VirtualRoot::try_new(root)?.virtual_join("").

Source

pub fn with_root_create<P: AsRef<Path>>(root: P) -> Result<Self>

Create the virtual root ("/"), creating the filesystem root if missing.

Sugar for VirtualRoot::try_new_create(root)?.virtual_join("").

Source

pub fn unvirtual(self) -> StrictPath<Marker>

Converts this VirtualPath back into a system-facing StrictPath.

Source

pub fn as_unvirtual(&self) -> &StrictPath<Marker>

Borrows the underlying system-facing StrictPath (no allocation).

Use this to pass a &VirtualPath to APIs that accept &StrictPath.

Source

pub fn interop_path(&self) -> &OsStr

Returns the underlying system path as &OsStr for AsRef<Path> interop.

Source

pub fn virtual_join<P: AsRef<Path>>(&self, path: P) -> Result<Self>

Safely joins a virtual path segment (virtual semantics) and re-validates.

Source

pub fn virtualpath_parent(&self) -> Result<Option<Self>>

Returns the parent virtual path, or None if at the virtual root.

Source

pub fn virtualpath_with_file_name<S: AsRef<OsStr>>( &self, file_name: S, ) -> Result<Self>

Returns a new VirtualPath with the file name changed, preserving clamping.

Source

pub fn virtualpath_with_extension<S: AsRef<OsStr>>( &self, extension: S, ) -> Result<Self>

Returns a new VirtualPath with the extension changed, preserving clamping.

Source

pub fn virtualpath_file_name(&self) -> Option<&OsStr>

Returns the file name component of the virtual path, if any.

Source

pub fn virtualpath_file_stem(&self) -> Option<&OsStr>

Returns the file stem of the virtual path, if any.

Source

pub fn virtualpath_extension(&self) -> Option<&OsStr>

Returns the extension of the virtual path, if any.

Source

pub fn virtualpath_starts_with<P: AsRef<Path>>(&self, p: P) -> bool

Returns true if the virtual path starts with the given prefix (virtual semantics).

Source

pub fn virtualpath_ends_with<P: AsRef<Path>>(&self, p: P) -> bool

Returns true if the virtual path ends with the given suffix (virtual semantics).

Source

pub fn virtualpath_display(&self) -> VirtualPathDisplay<'_, Marker>

Returns a Display wrapper that shows a rooted virtual path (e.g., "/a/b.txt").

Source

pub fn exists(&self) -> bool

Returns true if the underlying system path exists.

Source

pub fn is_file(&self) -> bool

Returns true if the underlying system path is a file.

Source

pub fn is_dir(&self) -> bool

Returns true if the underlying system path is a directory.

Source

pub fn metadata(&self) -> Result<Metadata>

Returns metadata for the underlying system path.

Source

pub fn read_to_string(&self) -> Result<String>

Reads the file contents as String from the underlying system path.

Source

pub fn read_bytes(&self) -> Result<Vec<u8>>

Reads the file contents as raw bytes from the underlying system path.

Source

pub fn write_bytes(&self, data: &[u8]) -> Result<()>

Writes raw bytes to the underlying system path.

Source

pub fn write_string(&self, data: &str) -> Result<()>

Writes a UTF-8 string to the underlying system path.

Source

pub fn create_dir_all(&self) -> Result<()>

Creates all directories in the underlying system path if missing.

Source

pub fn create_dir(&self) -> Result<()>

Creates the directory at this virtual location (non-recursive).

Mirrors std::fs::create_dir and fails if the parent does not exist.

Source

pub fn create_parent_dir(&self) -> Result<()>

Creates only the immediate parent directory of this virtual path (non-recursive).

Acts in the virtual dimension: the parent is derived via virtualpath_parent() and then created on the underlying system path. Returns Ok(()) at virtual root.

Source

pub fn create_parent_dir_all(&self) -> Result<()>

Recursively creates all missing directories up to the immediate parent of this virtual path.

Acts in the virtual dimension; returns Ok(()) at virtual root.

Source

pub fn remove_file(&self) -> Result<()>

Removes the file at the underlying system path.

Source

pub fn remove_dir(&self) -> Result<()>

Removes the directory at the underlying system path.

Source

pub fn remove_dir_all(&self) -> Result<()>

Recursively removes the directory and its contents at the underlying system path.

Source

pub fn virtual_rename<P: AsRef<Path>>(&self, dest: P) -> Result<Self>

Renames or moves this virtual path to a new location within the same virtual root.

Destination paths are resolved in virtual space:

  • Relative inputs are interpreted as siblings (resolved against the virtual parent).
  • Absolute virtual inputs are treated as requests from the virtual root.

Clamping and boundary checks are enforced by virtual joins. No parent directories are created implicitly; call create_parent_dir_all() beforehand if needed.

Trait Implementations§

Source§

impl<Marker: Clone> Clone for VirtualPath<Marker>

Source§

fn clone(&self) -> VirtualPath<Marker>

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<Marker> Debug for VirtualPath<Marker>

Source§

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

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

impl<Marker> Hash for VirtualPath<Marker>

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<Marker> Ord for VirtualPath<Marker>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<Marker> PartialEq<StrictPath<Marker>> for VirtualPath<Marker>

Source§

fn eq(&self, other: &StrictPath<Marker>) -> 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<T: AsRef<Path>, Marker> PartialEq<T> for VirtualPath<Marker>

Source§

fn eq(&self, other: &T) -> 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<Marker> PartialEq<VirtualPath<Marker>> for StrictPath<Marker>

Source§

fn eq(&self, other: &VirtualPath<Marker>) -> 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<Marker> PartialEq for VirtualPath<Marker>

Source§

fn eq(&self, other: &Self) -> 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<T: AsRef<Path>, Marker> PartialOrd<T> for VirtualPath<Marker>

Source§

fn partial_cmp(&self, other: &T) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<Marker> PartialOrd for VirtualPath<Marker>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<Marker> Eq for VirtualPath<Marker>

Auto Trait Implementations§

§

impl<Marker> Freeze for VirtualPath<Marker>

§

impl<Marker> RefUnwindSafe for VirtualPath<Marker>
where Marker: RefUnwindSafe,

§

impl<Marker> Send for VirtualPath<Marker>
where Marker: Send + Sync,

§

impl<Marker> Sync for VirtualPath<Marker>
where Marker: Sync + Send,

§

impl<Marker> Unpin for VirtualPath<Marker>
where Marker: Unpin,

§

impl<Marker> UnwindSafe for VirtualPath<Marker>
where Marker: UnwindSafe + RefUnwindSafe,

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