Skip to main content

LocalFilesystem

Struct LocalFilesystem 

Source
pub struct LocalFilesystem { /* private fields */ }
Expand description

Files under one root directory.

Every path is normalised and then joined to the root, and the result is checked to still be inside it. Two independent guards, because the consequence of getting it wrong is reading or writing anywhere the process can reach.

Implementations§

Source§

impl LocalFilesystem

Source

pub fn new(root: impl Into<PathBuf>) -> LocalFilesystem

Files under root.

Source

pub fn with_url_prefix(self, prefix: impl Into<String>) -> LocalFilesystem

The URL prefix files under this root are reachable at.

Only meaningful if something — nginx, a CDN, a route you wrote — actually serves the directory. Without it url is None, because a link that 404s is worse than no link.

Source

pub fn root(&self) -> &Path

The root directory.

Trait Implementations§

Source§

impl Debug for LocalFilesystem

Source§

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

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

impl Filesystem for LocalFilesystem

Source§

fn name(&self) -> &str

A label for diagnostics — "local", "s3", "memory".
Source§

fn get<'a>( &'a self, path: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, Error>> + Send + 'a>>

Read a file. None if it is not there. Read more
Source§

fn put<'a>( &'a self, path: &'a str, contents: Bytes, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>

Write a file, creating any directories it needs and replacing what was there.
Source§

fn delete<'a>( &'a self, path: &'a str, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a>>

Delete a file. true if it was there.
Source§

fn exists<'a>( &'a self, path: &'a str, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a>>

Whether a file exists.
Source§

fn metadata<'a>( &'a self, path: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<Metadata>, Error>> + Send + 'a>>

A file’s metadata, or None.
Source§

fn list<'a>( &'a self, prefix: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Metadata>, Error>> + Send + 'a>>

Every file directly under prefix, not recursing. Read more
Source§

fn rename<'a>( &'a self, from: &'a str, to: &'a str, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>

Move a file.
Source§

fn url(&self, path: &str) -> Option<String>

A URL a browser can fetch, if this driver has one. Read more
Source§

fn copy<'a>( &'a self, from: &'a str, to: &'a str, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>

Copy a file. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

fn event_name() -> &'static str
where Self: Sized,

A human-readable name, used by wildcard listeners and log output. Always the Rust type path; see the trait docs.
Source§

impl<F> FilesystemExt for F
where F: Filesystem + ?Sized,

Source§

fn get_string<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + 'async_trait,

Read a file as a string.
Source§

fn put_string<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, path: &'life1 str, contents: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: Sync + 'async_trait,

Write a string.
Source§

fn get_or_fail<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Bytes, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + 'async_trait,

Read a file, failing with a 404 if it is absent. Read more
Source§

fn size<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<u64>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + 'async_trait,

A file’s size.
Source§

fn last_modified<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<DateTime<Utc>>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + 'async_trait,

When a file was last written.
Source§

fn append<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, path: &'life1 str, contents: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: Sync + 'async_trait,

Append to a file, creating it if absent. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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