Skip to main content

Vfs

Struct Vfs 

Source
pub struct Vfs { /* private fields */ }

Implementations§

Source§

impl Vfs

Source

pub fn new() -> Self

Source

pub fn new_host_root(root: impl AsRef<Path>) -> Result<Self>

Project tree backed by a host directory (same path as the Lima workspace_parent mount).

§Errors

I/O errors from std::fs::create_dir_all or std::fs::canonicalize.

Source

pub const fn is_host_backed(&self) -> bool

true when this instance uses the host directory (Self::new_host_root) instead of the in-memory tree.

Source

pub const fn from_parts(root: Node, cwd: String) -> Self

Construct VFS from root node and cwd (used by deserialization).

Source

pub fn cwd(&self) -> &str

Source

pub const fn root(&self) -> &Node

Source

pub fn resolve_absolute(&self, path: &str) -> Result<Node, VfsError>

Resolve an absolute path to a node. Path must be absolute (normalized). Trailing ‘/’ is trimmed.

§Errors

Returns VfsError::InvalidPath if any segment is missing.

Source

pub fn resolve_to_absolute(&self, path: &str) -> String

将任意路径(相对或绝对)归一化并解析为绝对路径字符串。 相对路径先与 cwd 拼接再归一化,这样 “..” 能正确退到上级目录。

Source

pub fn mkdir(&mut self, path: &str) -> Result<(), VfsError>

Create directory at path (mkdir_all style). Creates any missing parent directories.

§Errors

Returns VfsError::InvalidPath if any path component exists and is not a directory.

Source

pub fn write_file(&mut self, path: &str, content: &[u8]) -> Result<(), VfsError>

Create or overwrite a file at path. Parent directory must exist and be a directory.

§Errors

Returns VfsError::InvalidPath if parent path does not exist or a component is not a directory.

Source

pub fn touch(&mut self, path: &str) -> Result<(), VfsError>

Create an empty file at path (touch). Parent directory must exist.

§Errors

Same as write_file.

Source

pub fn read_file(&self, path: &str) -> Result<Vec<u8>, VfsError>

Read file content at path.

§Errors

Returns VfsError::InvalidPath if path does not exist or is not a file.

Source

pub fn list_dir(&self, path: &str) -> Result<Vec<String>, VfsError>

List directory entries at path.

§Errors

Returns VfsError::InvalidPath if path does not exist or is not a directory.

Source

pub fn set_cwd(&mut self, path: &str) -> Result<(), VfsError>

Set current working directory to path.

§Errors

Returns VfsError::InvalidPath if path does not exist or is not a directory.

Source

pub fn copy_tree_to_host( &self, vfs_path: &str, host_dir: &Path, ) -> Result<(), VfsError>

Recursively copy the VFS subtree at vfs_path to the host directory host_dir. For each Dir creates a directory; for each File writes file content.

§Errors

Returns VfsError::InvalidPath if path does not exist; VfsError::Io on host I/O failure.

Trait Implementations§

Source§

impl Default for Vfs

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Vfs

§

impl RefUnwindSafe for Vfs

§

impl Send for Vfs

§

impl Sync for Vfs

§

impl Unpin for Vfs

§

impl UnsafeUnpin for Vfs

§

impl UnwindSafe for Vfs

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