aboutsummaryrefslogtreecommitdiff
path: root/src/table/schema.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-04-27 16:14:44 +0200
committerAlex Auvolat <alex@adnab.me>2023-06-09 16:23:37 +0200
commit6005491cd8adf569c0b7f88fc6b3af3f166963ea (patch)
treeb66f8a24d48eee04b43f0c20e58cb9c80696e903 /src/table/schema.rs
parentea3bfd2ab107497c47718dec3c6c6cda45cd1a43 (diff)
downloadgarage-6005491cd8adf569c0b7f88fc6b3af3f166963ea.tar.gz
garage-6005491cd8adf569c0b7f88fc6b3af3f166963ea.zip
Use Cow<[u8]> for sort keys
Diffstat (limited to 'src/table/schema.rs')
-rw-r--r--src/table/schema.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/table/schema.rs b/src/table/schema.rs
index 5cbf6c95..44b10898 100644
--- a/src/table/schema.rs
+++ b/src/table/schema.rs
@@ -1,3 +1,5 @@
+use std::borrow::Cow;
+
use serde::{Deserialize, Serialize};
use garage_db as db;
@@ -32,18 +34,18 @@ impl PartitionKey for FixedBytes32 {
/// Trait for field used to sort data
pub trait SortKey: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static {
/// Get the key used to sort
- fn sort_key(&self) -> &[u8];
+ fn sort_key(&self) -> Cow<'_, [u8]>;
}
impl SortKey for String {
- fn sort_key(&self) -> &[u8] {
- self.as_bytes()
+ fn sort_key(&self) -> Cow<'_, [u8]> {
+ Cow::from(self.as_bytes())
}
}
impl SortKey for FixedBytes32 {
- fn sort_key(&self) -> &[u8] {
- self.as_slice()
+ fn sort_key(&self) -> Cow<'_, [u8]> {
+ Cow::from(self.as_slice())
}
}