Skip to main content

VfsHostState

Struct VfsHostState 

Source
pub struct VfsHostState {
    pub wasi_ctx: WasiCtx,
    pub table: ResourceTable,
    pub shared_vfs: Arc<Fs>,
}
Expand description

Host state that uses fs-core directly for filesystem operations. Multiple instances can share the same VFS via Arc<Fs>.

Since fs-core uses DashMap internally with fine-grained locking, no external lock is required. All Fs methods take &self.

Fields§

§wasi_ctx: WasiCtx

WASI context for host operations (stdio, env, etc.)

§table: ResourceTable

Resource table for managing WASM resources

§shared_vfs: Arc<Fs>

Shared VFS: multiple VfsHostState instances can reference the same VFS No external lock needed - fs-core uses DashMap for internal thread safety

Implementations§

Source§

impl VfsHostState

Source

pub fn new() -> Result<Self>

Create a new VfsHostState with a fresh fs-core filesystem

Source

pub fn clone_shared(&self) -> Self

Create a new VfsHostState that shares the same VFS core This enables multiple applications to access the same VFS concurrently

Source

pub fn clone_shared_with_env(&self, env_vars: &[(&str, &str)]) -> Self

Create a new VfsHostState that shares the same VFS core with custom environment variables This enables passing configuration to WASM handlers

Source

pub fn from_shared_vfs_with_env( shared_vfs: Arc<Fs>, env_vars: &[(&str, &str)], ) -> Self

Create a new VfsHostState from an existing shared VFS with custom environment variables This is useful when sharing VFS across threads (e.g., in HTTP server handlers)

Source

pub fn get_shared_vfs(&self) -> Arc<Fs>

Get the shared VFS for external use (e.g., sharing across threads)

Trait Implementations§

Source§

impl Default for VfsHostState

Source§

fn default() -> Self

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

impl Host for VfsHostState

Source§

fn get_directories( &mut self, ) -> Result<Vec<(Resource<Descriptor>, String)>, Error>

Return the set of preopened directories, and their path.
Source§

impl Host for VfsHostState

Source§

fn filesystem_error_code( &mut self, err: Resource<Error>, ) -> Result<Option<ErrorCode>, Error>

Attempts to extract a filesystem-related error-code from the stream error provided. Read more
Source§

fn convert_error_code( &mut self, err: TrappableError<ErrorCode>, ) -> Result<ErrorCode, Error>

Source§

impl HostDescriptor for VfsHostState

Source§

fn read( &mut self, self_: Resource<Descriptor>, len: u64, offset: u64, ) -> Result<(Vec<u8>, bool), TrappableError<ErrorCode>>

Read from a descriptor, without using and updating the descriptor’s offset. Read more
Source§

fn write( &mut self, self_: Resource<Descriptor>, buffer: Vec<u8>, offset: u64, ) -> Result<u64, TrappableError<ErrorCode>>

Write to a descriptor, without using and updating the descriptor’s offset. Read more
Source§

fn drop(&mut self, rep: Resource<Descriptor>) -> Result<(), Error>

Source§

fn read_via_stream( &mut self, self_: Resource<Descriptor>, offset: u64, ) -> Result<Resource<Box<dyn HostInputStream>>, TrappableError<ErrorCode>>

Return a stream for reading from a file, if available. Read more
Source§

fn write_via_stream( &mut self, self_: Resource<Descriptor>, offset: u64, ) -> Result<Resource<Box<dyn HostOutputStream>>, TrappableError<ErrorCode>>

Return a stream for writing to a file, if available. Read more
Source§

fn append_via_stream( &mut self, self_: Resource<Descriptor>, ) -> Result<Resource<Box<dyn HostOutputStream>>, TrappableError<ErrorCode>>

Return a stream for appending to a file, if available. Read more
Source§

fn advise( &mut self, _self_: Resource<Descriptor>, _offset: u64, _len: u64, _advice: Advice, ) -> Result<(), TrappableError<ErrorCode>>

Provide file advisory information on a descriptor. Read more
Source§

fn sync_data( &mut self, _self_: Resource<Descriptor>, ) -> Result<(), TrappableError<ErrorCode>>

Synchronize the data of a file to disk. Read more
Source§

fn get_flags( &mut self, _self_: Resource<Descriptor>, ) -> Result<DescriptorFlags, TrappableError<ErrorCode>>

Get flags associated with a descriptor. Read more
Source§

fn get_type( &mut self, self_: Resource<Descriptor>, ) -> Result<DescriptorType, TrappableError<ErrorCode>>

Get the dynamic type of a descriptor. Read more
Source§

fn set_size( &mut self, self_: Resource<Descriptor>, size: u64, ) -> Result<(), TrappableError<ErrorCode>>

Adjust the size of an open file. If this increases the file’s size, the extra bytes are filled with zeros. Read more
Source§

fn set_times( &mut self, _self_: Resource<Descriptor>, _data_access_timestamp: NewTimestamp, _data_modification_timestamp: NewTimestamp, ) -> Result<(), TrappableError<ErrorCode>>

Adjust the timestamps of an open file or directory. Read more
Source§

fn set_times_at( &mut self, _self_: Resource<Descriptor>, _path_flags: PathFlags, _path: String, _data_access_timestamp: NewTimestamp, _data_modification_timestamp: NewTimestamp, ) -> Result<(), TrappableError<ErrorCode>>

Adjust the timestamps of a file or directory. Read more
Source§

fn read_directory( &mut self, self_: Resource<Descriptor>, ) -> Result<Resource<DirectoryEntryStream>, TrappableError<ErrorCode>>

Read directory entries from a directory. Read more
Source§

fn sync( &mut self, _self_: Resource<Descriptor>, ) -> Result<(), TrappableError<ErrorCode>>

Synchronize the data and metadata of a file to disk. Read more
Source§

fn create_directory_at( &mut self, self_: Resource<Descriptor>, path: String, ) -> Result<(), TrappableError<ErrorCode>>

Create a directory. Read more
Source§

fn stat( &mut self, self_: Resource<Descriptor>, ) -> Result<DescriptorStat, TrappableError<ErrorCode>>

Return the attributes of an open file or directory. Read more
Source§

fn stat_at( &mut self, self_: Resource<Descriptor>, _path_flags: PathFlags, path: String, ) -> Result<DescriptorStat, TrappableError<ErrorCode>>

Return the attributes of a file or directory. Read more
Create a hard link. Read more
Source§

fn open_at( &mut self, self_: Resource<Descriptor>, _path_flags: PathFlags, path: String, open_flags: OpenFlags, flags: DescriptorFlags, ) -> Result<Resource<Descriptor>, TrappableError<ErrorCode>>

Open a file or directory. Read more
Read the contents of a symbolic link. Read more
Source§

fn remove_directory_at( &mut self, self_: Resource<Descriptor>, path: String, ) -> Result<(), TrappableError<ErrorCode>>

Remove a directory. Read more
Source§

fn rename_at( &mut self, self_: Resource<Descriptor>, old_path: String, _new_descriptor: Resource<Descriptor>, new_path: String, ) -> Result<(), TrappableError<ErrorCode>>

Rename a filesystem object. Read more
Create a symbolic link (also known as a “symlink”). Read more
Unlink a filesystem object that is not a directory. Read more
Source§

fn is_same_object( &mut self, self_: Resource<Descriptor>, other: Resource<Descriptor>, ) -> Result<bool, Error>

Test whether two descriptors refer to the same filesystem object. Read more
Source§

fn metadata_hash( &mut self, self_: Resource<Descriptor>, ) -> Result<MetadataHashValue, TrappableError<ErrorCode>>

Return a hash of the metadata associated with a filesystem object referred to by a descriptor. Read more
Source§

fn metadata_hash_at( &mut self, self_: Resource<Descriptor>, _path_flags: PathFlags, path: String, ) -> Result<MetadataHashValue, TrappableError<ErrorCode>>

Return a hash of the metadata associated with a filesystem object referred to by a directory descriptor and a relative path. Read more
Source§

impl HostDirectoryEntryStream for VfsHostState

Source§

fn read_directory_entry( &mut self, self_: Resource<DirectoryEntryStream>, ) -> Result<Option<DirectoryEntry>, TrappableError<ErrorCode>>

Read a single directory entry from a directory-entry-stream.
Source§

fn drop(&mut self, rep: Resource<DirectoryEntryStream>) -> Result<(), Error>

Source§

impl WasiView for VfsHostState

Source§

fn ctx(&mut self) -> &mut WasiCtx

Yields mutable access to the configuration used for this context. Read more
Source§

fn table(&mut self) -> &mut ResourceTable

Yields mutable access to the internal resource management that this context contains. Read more

Auto Trait Implementations§

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> GetSetFdFlags for T

Source§

fn get_fd_flags(&self) -> Result<FdFlags, Error>
where T: AsFilelike,

Query the “status” flags for the self file descriptor.
Source§

fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>
where T: AsFilelike,

Create a new SetFdFlags value for use with set_fd_flags. Read more
Source§

fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>
where T: AsFilelike,

Set the “status” flags for the self file descriptor. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Pointer = u32

Source§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more