pub struct Disk { /* private fields */ }Implementations§
Source§impl Disk
impl Disk
Sourcepub async fn put(&self, path: &str, contents: &[u8]) -> Result<(), AppError>
pub async fn put(&self, path: &str, contents: &[u8]) -> Result<(), AppError>
Writes contents to path, lazily creating any missing parent
directories first (tokio::fs::create_dir_all) - a disk’s root
(or any subdirectory under it, e.g. uploads/) need not already
exist on disk before the first put().
Sourcepub async fn get(&self, path: &str) -> Result<Option<Vec<u8>>, AppError>
pub async fn get(&self, path: &str) -> Result<Option<Vec<u8>>, AppError>
Returns Ok(None) for a missing file - not an error, the same
“a miss is a normal outcome” shape larust_cache::get’s own
Result<Option<T>, AppError> already established. A real I/O
failure (permissions, a disk error) is still Err.
pub async fn exists(&self, path: &str) -> Result<bool, AppError>
Sourcepub async fn delete(&self, path: &str) -> Result<(), AppError>
pub async fn delete(&self, path: &str) -> Result<(), AppError>
Not an error to delete a key that’s already gone - same shape as
larust_cache::forget’s own “not an error to forget an
already-missing key” precedent.
Sourcepub fn url(&self, path: &str) -> Result<Option<String>, AppError>
pub fn url(&self, path: &str) -> Result<Option<String>, AppError>
Ok(None) on local() (nothing under storage/app/ is ever
served); Ok(Some(...))-with-a-/-prefixed, directly
request-usable path on public(). Runs path through the same
validation put/get/exists/delete do - an earlier version
of this method skipped that check entirely, which was inconsistent
(every other Disk method validates its path) without being
itself a traversal bug (url() never touches disk) - still worth
closing so a caller can’t be misled into building a URL for a path
that put/get would actually reject. Does not check that path
already exists as a file - a URL can be built for one about to
be put().
Auto Trait Implementations§
impl Freeze for Disk
impl RefUnwindSafe for Disk
impl Send for Disk
impl Sync for Disk
impl Unpin for Disk
impl UnsafeUnpin for Disk
impl UnwindSafe for Disk
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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