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().