heed_types/
str.rs

1use std::borrow::Cow;
2use std::str;
3
4use heed_traits::{BoxedError, BytesDecode, BytesEncode};
5
6/// Describes a [`prim@str`].
7pub enum Str {}
8
9impl BytesEncode<'_> for Str {
10    type EItem = str;
11
12    fn bytes_encode(item: &Self::EItem) -> Result<Cow<[u8]>, BoxedError> {
13        Ok(Cow::Borrowed(item.as_bytes()))
14    }
15}
16
17impl<'a> BytesDecode<'a> for Str {
18    type DItem = &'a str;
19
20    fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, BoxedError> {
21        str::from_utf8(bytes).map_err(Into::into)
22    }
23}