Skip to main content

Files

Trait Files 

Source
pub trait Files:
    Send
    + Sync
    + 'static {
    // Required methods
    fn write_file(&self, name: &str, bytes: &[u8]) -> Result<()>;
    fn append_file(&self, name: &str, bytes: &[u8]) -> Result<()>;
    fn read_file(&self, name: &str) -> Result<Vec<u8>>;
    fn remove_file(&self, name: &str) -> Result<()>;
    fn files(&self) -> Result<Vec<String>>;
}
Expand description

A place that keeps files by name, such as a session’s plugin data or effect log. A name is relative and /-separated (check_name). Every method takes &self, so one value is shared, between threads on every target: a host keeps it as Arc<dyn Files> or Arc<dyn Store> in state its systems share, such as a Bevy resource, which is Send and Sync on wasm too; Arc<dyn Store> and Box<dyn Store> are themselves a Store, so an AsyncStore too. A store that is not Send and Sync, such as one over a JavaScript promise, is an AsyncStore.

Required Methods§

Source

fn write_file(&self, name: &str, bytes: &[u8]) -> Result<()>

Replaces the file name with bytes, atomically: a reader sees the old content or the new.

Source

fn append_file(&self, name: &str, bytes: &[u8]) -> Result<()>

Adds bytes at the end of the file name, which it creates when there is none.

Source

fn read_file(&self, name: &str) -> Result<Vec<u8>>

The file name; io::ErrorKind::NotFound when there is none.

Source

fn remove_file(&self, name: &str) -> Result<()>

Removes the file name; removing one that is not there succeeds.

Source

fn files(&self) -> Result<Vec<String>>

The names of the files, in no particular order.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<S: Files + ?Sized> Files for Arc<S>

Source§

fn write_file(&self, name: &str, bytes: &[u8]) -> Result<()>

Source§

fn append_file(&self, name: &str, bytes: &[u8]) -> Result<()>

Source§

fn read_file(&self, name: &str) -> Result<Vec<u8>>

Source§

fn remove_file(&self, name: &str) -> Result<()>

Source§

fn files(&self) -> Result<Vec<String>>

Source§

impl<S: Files + ?Sized> Files for Box<S>

Source§

fn write_file(&self, name: &str, bytes: &[u8]) -> Result<()>

Source§

fn append_file(&self, name: &str, bytes: &[u8]) -> Result<()>

Source§

fn read_file(&self, name: &str) -> Result<Vec<u8>>

Source§

fn remove_file(&self, name: &str) -> Result<()>

Source§

fn files(&self) -> Result<Vec<String>>

Implementors§