Skip to main content

StoreError

Enum StoreError 

Source
#[non_exhaustive]
pub enum StoreError { WrongType, NotInteger, Overflow, OutOfRange, NoSuchKey, NotFloat, OutOfMemory, StreamExhausted, }
Expand description

Operation errors surfaced to the command layer.

Display is the lowercase description; StoreError::as_wire is the Redis error reply text the command layer sends.

use kevy_store::StoreError;
assert_eq!(StoreError::WrongType.to_string(), "wrong type for this operation");
assert!(StoreError::WrongType.as_wire().starts_with("WRONGTYPE "));

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

WrongType

Key holds a different type than the command expects.

use kevy_store::{Store, StoreError};
let mut s = Store::new();
s.rpush(b"l", &[b"x".as_slice()])?;
assert_eq!(s.get(b"l"), Err(StoreError::WrongType));
§

NotInteger

Value is not a base-10 integer (INCR family).

use kevy_store::{SetCondition, Store, StoreError};
let mut s = Store::new();
s.set(b"k", b"ten".to_vec(), None, SetCondition::Always);
assert_eq!(s.incr_by(b"k", 1), Err(StoreError::NotInteger));
§

Overflow

Result would overflow i64.

use kevy_store::{SetCondition, Store, StoreError};
let mut s = Store::new();
s.set(b"k", i64::MAX.to_string().into_bytes(), None, SetCondition::Always);
assert_eq!(s.incr_by(b"k", 1), Err(StoreError::Overflow));
§

OutOfRange

Index outside the collection (LSET).

use kevy_store::{Store, StoreError};
let mut s = Store::new();
s.rpush(b"l", &[b"a".as_slice()])?;
assert_eq!(s.lset(b"l", 5, b"x"), Err(StoreError::OutOfRange));
§

NoSuchKey

Key does not exist where the command requires one (LSET).

use kevy_store::{Store, StoreError};
let mut s = Store::new();
assert_eq!(s.lset(b"missing", 0, b"x"), Err(StoreError::NoSuchKey));
§

NotFloat

Value is not a valid float (INCRBYFLOAT).

use kevy_store::{SetCondition, Store, StoreError};
let mut s = Store::new();
s.set(b"k", b"pi".to_vec(), None, SetCondition::Always);
assert_eq!(s.incr_by_float(b"k", 1.0), Err(StoreError::NotFloat));
§

OutOfMemory

maxmemory would be exceeded and the active eviction policy is EvictionPolicy::NoEviction. Surfaces as Redis’s classic OOM error at the RESP layer.

use kevy_store::{EvictionPolicy, SetCondition, Store, StoreError};
let mut s = Store::new();
s.set_max_memory(1, EvictionPolicy::NoEviction);
s.set(b"k", b"v".to_vec(), None, SetCondition::Always);
assert_eq!(s.precheck_for_write(), Err(StoreError::OutOfMemory));
§

StreamExhausted

A stream’s last ID is the largest there is, so no entry can follow it (XADD).

use kevy_store::{MissingStream, Store, StoreError, StreamId, XAddIdSpec};
let mut s = Store::new();
let f = || vec![(b"f".to_vec(), b"v".to_vec())];
s.xadd(b"s", XAddIdSpec::Explicit(StreamId::MAX), f(), MissingStream::Create, 0)?;
let next = s.xadd(b"s", XAddIdSpec::AutoAll, f(), MissingStream::Create, 0);
assert_eq!(next, Err(StoreError::StreamExhausted));

Implementations§

Source§

impl StoreError

Source

pub fn as_wire(&self) -> &'static str

The Redis error reply text for this error, prefix included (WRONGTYPE …, ERR …, OOM …) — what a RESP layer writes after the -.

assert_eq!(kevy_store::StoreError::NoSuchKey.as_wire(), "ERR no such key");

Trait Implementations§

Source§

impl Clone for StoreError

Source§

fn clone(&self) -> StoreError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for StoreError

Source§

impl Debug for StoreError

Source§

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

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

impl Display for StoreError

Source§

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

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

impl Eq for StoreError

Source§

impl Error for StoreError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<StoreError> for KevyError

Source§

fn from(e: StoreError) -> KevyError

Converts to this type from the input type.
Source§

impl Hash for StoreError

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for StoreError

Source§

fn eq(&self, other: &StoreError) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for StoreError

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.