pub struct Storage { /* private fields */ }Expand description
A celerix Storage handle backed by Cloudflare Workers KV.
Injected automatically as an axum Extension<Storage> by #[celerix::main].
The binding is auto-resolved to {PROJECT_NAME}_STORAGE.
KV is initialized lazily on first use, so projects that don’t use storage won’t error even without a KV binding configured.
Implementations§
Source§impl Storage
impl Storage
Sourcepub fn get(
&self,
key: &str,
) -> SendFuture<impl Future<Output = Result<Option<String>, Error>>> ⓘ
pub fn get( &self, key: &str, ) -> SendFuture<impl Future<Output = Result<Option<String>, Error>>> ⓘ
Get a string value by key.
Sourcepub fn put(
&self,
key: &str,
value: &str,
) -> SendFuture<impl Future<Output = Result<(), Error>>> ⓘ
pub fn put( &self, key: &str, value: &str, ) -> SendFuture<impl Future<Output = Result<(), Error>>> ⓘ
Put a string value.
Sourcepub fn delete(
&self,
key: &str,
) -> SendFuture<impl Future<Output = Result<(), Error>>> ⓘ
pub fn delete( &self, key: &str, ) -> SendFuture<impl Future<Output = Result<(), Error>>> ⓘ
Delete a key.
Sourcepub fn get_item<T>(
&self,
key: &str,
) -> SendFuture<impl Future<Output = Result<Option<T>, Error>>> ⓘwhere
T: DeserializeOwned + 'static,
pub fn get_item<T>(
&self,
key: &str,
) -> SendFuture<impl Future<Output = Result<Option<T>, Error>>> ⓘwhere
T: DeserializeOwned + 'static,
Get a JSON-deserialized value by key.
ⓘ
let user: Option<User> = storage.get_item::<User>("user:123").await?;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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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