pub enum Error {
NotFound,
InvalidArgument(String),
WrongType {
expected: &'static str,
got: &'static str,
},
Encode(String),
Decode(String),
}Expand description
Errors returned by heaplet operations.
Most APIs return Result<_, Error>. Common failure modes:
Error::WrongType: the key exists but stores a different structure typeError::NotFound: an operation requires a key/element to existError::InvalidArgument: invalid input such as out-of-range indicesError::Encode/Error::Decode: codec failures when converting values
§Example
use heaplet::{Error, Store};
let store = Store::new();
// Create a hash under "k".
store.hash("k").hset("f", &1_i64).unwrap();
// Now try to use "k" as a KV/String key => WrongType.
let err = store.kv().get::<i64>("k").unwrap_err();
match err {
Error::WrongType { expected, got } => {
assert_eq!(expected, "string");
assert_eq!(got, "hash");
}
other => panic!("unexpected error: {other}"),
}Variants§
NotFound
The requested key or element was not found.
InvalidArgument(String)
The caller provided an invalid argument (e.g. out-of-range index).
WrongType
The operation was attempted on a key holding a different value type.
Fields
Encode(String)
Encoding failed.
Decode(String)
Decoding failed.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
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