pub use bytes::Bytes;
mod error;
mod traits;
pub use error::LLError;
pub use traits::{LLPath, LLReader, LLStore, LLWriter};
#[cfg(feature = "async")]
mod async_traits;
#[cfg(feature = "async")]
pub use async_traits::{AsyncLLReader, AsyncLLStore, AsyncLLWriter, SyncToAsyncLL};
pub fn ll_path(components: &[&[u8]]) -> LLPath {
components
.iter()
.map(|c| Bytes::copy_from_slice(c))
.collect()
}
pub fn ll_path_from_strs(components: &[&str]) -> LLPath {
components
.iter()
.map(|s| Bytes::copy_from_slice(s.as_bytes()))
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ll_path_creates_owned_path() {
let path = ll_path(&[b"users", b"123"]);
assert_eq!(path.len(), 2);
assert_eq!(path[0].as_ref(), b"users");
assert_eq!(path[1].as_ref(), b"123");
}
#[test]
fn ll_path_from_strs_creates_owned_path() {
let path = ll_path_from_strs(&["users", "alice"]);
assert_eq!(path.len(), 2);
assert_eq!(path[0].as_ref(), b"users");
assert_eq!(path[1].as_ref(), b"alice");
}
#[test]
fn ll_path_empty() {
let path = ll_path(&[]);
assert!(path.is_empty());
}
#[test]
fn ll_path_from_strs_empty() {
let path = ll_path_from_strs(&[]);
assert!(path.is_empty());
}
#[test]
fn llpath_newtype_construction_and_views() {
let raw = vec![Bytes::from_static(b"a"), Bytes::from_static(b"b")];
let path = LLPath::from_components(raw.clone());
assert_eq!(path.components(), raw.as_slice());
assert_eq!(path.clone().into_components(), raw);
assert_eq!(path.len(), 2);
assert_eq!(path[0].as_ref(), b"a");
assert_eq!(path.iter().count(), 2);
assert_eq!(path.as_byte_refs(), vec![b"a".as_ref(), b"b".as_ref()]);
}
#[test]
fn llpath_from_iter_and_into_iter() {
let path: LLPath = [Bytes::from_static(b"x"), Bytes::from_static(b"y")]
.into_iter()
.collect();
assert_eq!(path.len(), 2);
let components: Vec<Vec<u8>> = path.into_iter().map(|b| b.to_vec()).collect();
assert_eq!(components, vec![b"x".to_vec(), b"y".to_vec()]);
}
#[test]
fn llpath_push_grows() {
let mut path = LLPath::new();
assert!(path.is_empty());
path.push(Bytes::from_static(b"only"));
assert_eq!(path.len(), 1);
assert_eq!(path[0].as_ref(), b"only");
}
}