pub struct EmbedFilesystem { /* private fields */ }Expand description
A filesystem implementation that reads from embedded files.
This filesystem provides read-only access to files that have been embedded
into the binary at compile time using rust-embed.
Implementations§
Source§impl EmbedFilesystem
impl EmbedFilesystem
Sourcepub fn new(provider: Box<dyn EmbedFilesystemProvider>) -> Self
pub fn new(provider: Box<dyn EmbedFilesystemProvider>) -> Self
Sourcepub fn with_root_dir(self, root_dir: &str) -> Self
pub fn with_root_dir(self, root_dir: &str) -> Self
Sets the root directory for this filesystem.
When a root directory is set, all file path lookups will be prefixed with this directory path. Trailing slashes and backslashes are automatically normalized to ensure consistent path formatting.
§Arguments
root_dir- The root directory path to use as a prefix
§Returns
Self with the root directory configured
§Examples
struct MockProvider;
impl EmbedFilesystemProvider for MockProvider {
fn get(&self, _path: &str) -> Option<rust_embed::EmbeddedFile> { None }
}
let fs = EmbedFilesystem::new(Box::new(MockProvider))
.with_root_dir("assets/");Trait Implementations§
Source§impl Filesystem for EmbedFilesystem
impl Filesystem for EmbedFilesystem
Source§fn read_bytes<'life0, 'life1, 'async_trait>(
&'life0 self,
asset_path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, FilesystemError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn read_bytes<'life0, 'life1, 'async_trait>(
&'life0 self,
asset_path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, FilesystemError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Reads the contents of an embedded file as bytes.
§Arguments
asset_path- The path to the asset file to read
§Returns
The file contents as a Vec<u8> on success, or a FilesystemError
if the file is not found.
§Errors
Returns FilesystemError::NotFound if the requested file path
does not exist in the embedded files.
Source§fn write_bytes<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
asset_path: &'life1 str,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), FilesystemError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn write_bytes<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
asset_path: &'life1 str,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), FilesystemError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Asynchronously writes raw bytes to an asset file. Read more
Auto Trait Implementations§
impl Freeze for EmbedFilesystem
impl !RefUnwindSafe for EmbedFilesystem
impl Send for EmbedFilesystem
impl Sync for EmbedFilesystem
impl Unpin for EmbedFilesystem
impl UnsafeUnpin for EmbedFilesystem
impl !UnwindSafe for EmbedFilesystem
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
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.