pub struct Storage { /* private fields */ }Expand description
A file storage disk: state.storage, or a named one from
state.disk_named(name).
Implementations§
Source§impl Storage
impl Storage
Sourcepub async fn put(&self, key: &str, bytes: Bytes) -> Result
pub async fn put(&self, key: &str, bytes: Bytes) -> Result
Writes bytes to key, replacing any file there.
Sourcepub async fn get(&self, key: &str) -> Result<Option<Bytes>>
pub async fn get(&self, key: &str) -> Result<Option<Bytes>>
The file’s bytes, or None if there is no such key.
Sourcepub async fn delete(&self, key: &str) -> Result
pub async fn delete(&self, key: &str) -> Result
Deletes the file; deleting a missing key is not an error.
Sourcepub async fn list(&self, prefix: &str) -> Result<Vec<FileInfo>>
pub async fn list(&self, prefix: &str) -> Result<Vec<FileInfo>>
The URL of a public file (a key under public/).
The files under prefix (a folder like invoices/2026, or ""
for all), at any depth, sorted by key.
for file in state.storage.list("invoices/2026").await? {
println!("{} ({} bytes)", file.key, file.size);
}
state.storage.copy("public/logo.png", "public/logo-old.png").await?;
state.storage.rename("uploads/tmp/a.pdf", "invoices/2026/a.pdf").await?;
let removed = state.storage.delete_all("uploads/tmp").await?;Sourcepub async fn size(&self, key: &str) -> Result<Option<u64>>
pub async fn size(&self, key: &str) -> Result<Option<u64>>
The size of a file in bytes, if it exists.
Sourcepub async fn copy(&self, from: &str, to: &str) -> Result
pub async fn copy(&self, from: &str, to: &str) -> Result
Copies a file, replacing to if it exists. A missing from is a
404.
Sourcepub async fn rename(&self, from: &str, to: &str) -> Result
pub async fn rename(&self, from: &str, to: &str) -> Result
Moves a file (Laravel’s move), replacing to if it exists. A
missing from is a 404.
Sourcepub async fn delete_all(&self, prefix: &str) -> Result<usize>
pub async fn delete_all(&self, prefix: &str) -> Result<usize>
Deletes every file under prefix (not "": that would be all of
them); returns how many.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Storage
impl RefUnwindSafe for Storage
impl Send for Storage
impl Sync for Storage
impl Unpin for Storage
impl UnsafeUnpin for Storage
impl UnwindSafe for Storage
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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 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> ⓘ
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