Skip to content

Commit

Permalink
Use Cow string as will be utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
ktdlr committed Oct 22, 2024
1 parent 24881bb commit 4344754
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/ciphernode/data/src/data_store.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use crate::{InMemStore, IntoKey, SledStore};
use actix::{Addr, Message, Recipient};
use anyhow::Result;
Expand Down Expand Up @@ -58,7 +60,7 @@ impl DataStore {
/// Writes data to the scope location
pub fn write<T: Serialize>(&self, value: T) {
let Ok(serialized) = bincode::serialize(&value) else {
let str_key = self.get_scope().unwrap_or("<bad key>".to_string());
let str_key = self.get_scope().unwrap_or(Cow::Borrowed("<bad key>"));
let str_error = format!("Could not serialize value passed to {}", str_key);
error!(str_error);
return;
Expand All @@ -68,8 +70,8 @@ impl DataStore {
}

/// Get the scope as a string
pub fn get_scope(&self) -> Result<String> {
Ok(String::from_utf8(self.scope.clone())?)
pub fn get_scope(&self) -> Result<Cow<str>> {
Ok(String::from_utf8_lossy(&self.scope))
}

/// Changes the scope for the data store.
Expand Down

0 comments on commit 4344754

Please sign in to comment.