-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new trait to encode values to bytes
still lots of TODOs
- Loading branch information
Showing
10 changed files
with
245 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
use std::borrow::Cow; | ||
use std::str; | ||
use std::convert::Infallible; | ||
|
||
use heed_traits::{BoxedError, BytesDecode, BytesEncode}; | ||
use heed_traits::{BoxedError, BytesDecode, ToBytes}; | ||
|
||
/// Describes a [`prim@str`]. | ||
/// Describes a [`str`]. | ||
pub enum Str {} | ||
|
||
impl BytesEncode<'_> for Str { | ||
type EItem = str; | ||
impl<'a> ToBytes<'a> for Str { | ||
type SelfType = str; | ||
|
||
fn bytes_encode(item: &Self::EItem) -> Result<Cow<[u8]>, BoxedError> { | ||
Ok(Cow::Borrowed(item.as_bytes())) | ||
type ReturnBytes = &'a [u8]; | ||
|
||
type Error = Infallible; | ||
|
||
fn to_bytes(item: &'a Self::SelfType) -> Result<Self::ReturnBytes, Self::Error> { | ||
Ok(item.as_bytes()) | ||
} | ||
} | ||
|
||
impl<'a> BytesDecode<'a> for Str { | ||
type DItem = &'a str; | ||
|
||
fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, BoxedError> { | ||
str::from_utf8(bytes).map_err(Into::into) | ||
std::str::from_utf8(bytes).map_err(Into::into) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.