diff options
author | Vika <vika@fireburn.ru> | 2023-06-22 20:25:28 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2023-06-22 20:25:28 +0300 |
commit | ff358723da641af9f4ae1f742eb1b382f4630220 (patch) | |
tree | 32a2319a0bea909b9d267e44fa3a632991ddda12 /kittybox-rs/src/database/memory.rs | |
parent | 0285e630f3cae1ee2df2c7c465998b1ce669944f (diff) | |
download | kittybox-ff358723da641af9f4ae1f742eb1b382f4630220.tar.zst |
StorageError: use std::borrow::Cow for msg field
This allows avoiding an unnecessary allocation whenever the error message is static.
Diffstat (limited to 'kittybox-rs/src/database/memory.rs')
-rw-r--r-- | kittybox-rs/src/database/memory.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/kittybox-rs/src/database/memory.rs b/kittybox-rs/src/database/memory.rs index 2fb55e5..9d79ecc 100644 --- a/kittybox-rs/src/database/memory.rs +++ b/kittybox-rs/src/database/memory.rs @@ -46,7 +46,7 @@ impl Storage for MemoryStorage { let key: &str = match post["properties"]["uid"][0].as_str() { Some(uid) => uid, None => { - return Err(StorageError::new( + return Err(StorageError::from_static( ErrorKind::Other, "post doesn't have a UID", )) @@ -108,7 +108,7 @@ impl Storage for MemoryStorage { .or_default() .extend(v.clone()); } else { - return Err(StorageError::new( + return Err(StorageError::from_static( ErrorKind::BadRequest, "Malformed update object", )); @@ -120,7 +120,7 @@ impl Storage for MemoryStorage { if v.is_array() { add_keys.insert(k.to_string(), v.clone()); } else { - return Err(StorageError::new( + return Err(StorageError::from_static( ErrorKind::BadRequest, "Malformed update object", )); @@ -139,7 +139,7 @@ impl Storage for MemoryStorage { if let Some(new_post) = mapping.get(url) { post = new_post } else { - return Err(StorageError::new( + return Err(StorageError::from_static( ErrorKind::NotFound, "The post you have requested is not found in the database.", )); @@ -191,7 +191,7 @@ impl Storage for MemoryStorage { post, ); } else { - return Err(StorageError::new( + return Err(StorageError::from_static( ErrorKind::NotFound, "The designated post wasn't found in the database.", )); |