Skip to content

Commit

Permalink
Merge branch 'main' into generic-blob-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed Dec 5, 2024
2 parents 8cce69d + 63e9d4e commit 518bb2b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "value-log"
description = "Value log implementation for key-value separated LSM storage"
license = "MIT OR Apache-2.0"
version = "1.3.0"
version = "1.4.0"
edition = "2021"
rust-version = "1.74.0"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions src/gc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// This source code is licensed under both the Apache 2.0 and MIT License
// (found in the LICENSE-* files in the repository)

use crate::{id::SegmentId, BlobCache, Compressor, ValueLog};

pub mod report;

use crate::{id::SegmentId, Compressor, ValueLog};

/// GC strategy
#[allow(clippy::module_name_repetitions)]
pub trait GcStrategy<BC: BlobCache, C: Compressor + Clone> {
Expand Down
40 changes: 37 additions & 3 deletions src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ mod slice_arc;
#[cfg(feature = "bytes")]
mod slice_bytes;

use std::sync::Arc;
use std::{
path::{Path, PathBuf},
sync::Arc,
};

#[cfg(not(feature = "bytes"))]
pub use slice_arc::Slice;
Expand All @@ -27,12 +30,36 @@ impl From<&[u8]> for Slice {
}
}

impl From<&Vec<u8>> for Slice {
fn from(value: &Vec<u8>) -> Self {
Self::from(value.as_slice())
}
}

impl From<&str> for Slice {
fn from(value: &str) -> Self {
Self::from(value.as_bytes())
}
}

impl From<&String> for Slice {
fn from(value: &String) -> Self {
Self::from(value.as_str())
}
}

impl From<&Path> for Slice {
fn from(value: &Path) -> Self {
Self::from(value.as_os_str().as_encoded_bytes())
}
}

impl From<PathBuf> for Slice {
fn from(value: PathBuf) -> Self {
Self::from(value.as_os_str().as_encoded_bytes())
}
}

impl From<Arc<str>> for Slice {
fn from(value: Arc<str>) -> Self {
Self::from(&*value)
Expand All @@ -45,6 +72,12 @@ impl<const N: usize> From<[u8; N]> for Slice {
}
}

impl<const N: usize> From<&[u8; N]> for Slice {
fn from(value: &[u8; N]) -> Self {
Self::from(value.as_slice())
}
}

impl FromIterator<u8> for Slice {
fn from_iter<T>(iter: T) -> Self
where
Expand Down Expand Up @@ -143,6 +176,7 @@ mod serde {
}

#[cfg(test)]
#[allow(clippy::expect_used)]
mod tests {
use super::Slice;
use std::{fmt::Debug, sync::Arc};
Expand Down Expand Up @@ -185,8 +219,8 @@ mod tests {
assert_eq!(slice.as_ref(), arc_str.as_bytes());

// - io::Read
let reader = std::io::Cursor::new(vec![1, 2, 3, 4]);
let slice = Slice::from_reader(&mut reader.clone(), 4).expect("read");
let mut reader = std::io::Cursor::new(vec![1, 2, 3, 4]);
let slice = Slice::from_reader(&mut reader, 4).expect("read");
assert_eq!(slice, vec![1, 2, 3, 4]);
}
}

0 comments on commit 518bb2b

Please sign in to comment.