chore: some docs clean-up

This commit is contained in:
Dylan Bowker
2024-05-12 08:39:41 -06:00
committed by Vincent Herlemont
parent 646673efda
commit dac9ddb4c0
7 changed files with 40 additions and 31 deletions
+2 -1
View File
@@ -32,7 +32,8 @@ criterion = { version = "0.5.1" }
skeptic = "0.13.7"
[features]
default = ["serde", "bincode_1_3"]
# default = ["serde", "bincode_1_3"]
default = ["serde", "bincode_1_3", "bincode_2_rc", "postcard_1_0", "rmp_serde_1_3"]
[[bench]]
name = "overhead"
@@ -1,4 +1,4 @@
//! ⚠️ [`Read the docs before using`](crate::bincode_1_3::Bincode#warning).
//! ⚠️ [`Read the docs before using`](crate::bincode_1_3::Bincode#warning) -
//! Annotate your type with `native_model::bincode_1_3::Bincode` to use the
//! bincode 1.3 crate for serializing & deserializing.
@@ -1,4 +1,4 @@
//! ⚠️ [`Read the docs before using`](crate::bincode_2_rc::Bincode#warning).
//! ⚠️ [`Read the docs before using`](crate::bincode_2_rc::Bincode#warning) -
//! Annotate your type with `native_model::bincode_2_rc::Bincode` to use
//! the bincode 2.0.0-rc.3 crate for serializing & deserializing.
+13 -1
View File
@@ -14,7 +14,7 @@ pub mod rmp_serde_1_3;
///
/// Example:
/// ```rust
/// use bincode_2_rc::{error::EncodeError,serde::encode_to_vec, config::standard};
/// use bincode_2_rc::{error::EncodeError,serde::encode_to_vec, config::standard};
/// use serde::Serialize;
/// pub struct Bincode;
///
@@ -27,6 +27,12 @@ pub mod rmp_serde_1_3;
/// ```
pub trait Encode<T> {
type Error;
/// Encodes a `T` type into a series of bytes.
///
/// # Errors
///
/// The errors returned from this function depend on the trait implementor
/// (the serializer), i.e. `bincode_2_rc`.
fn encode(obj: &T) -> Result<Vec<u8>, Self::Error>;
}
@@ -46,5 +52,11 @@ pub trait Encode<T> {
/// }
pub trait Decode<T> {
type Error;
/// Decodes a series of bytes back into a `T` type.
///
/// # Errors
///
/// The errors returned from this function depend on the trait implementor
/// (the deserializer), i.e. `bincode_2_rc`.
fn decode(data: Vec<u8>) -> Result<T, Self::Error>;
}
@@ -1,4 +1,4 @@
//! ⚠️ [`Read the docs before using`](crate::postcard_1_0::PostCard#warning).
//! ⚠️ [`Read the docs before using`](crate::postcard_1_0::PostCard#warning) -
//! Annotate your type with `native_model::postcard_1_0::PostCard` to
//! use the postcard 1.0 crate for serializing & deserializing.
+21 -25
View File
@@ -17,7 +17,8 @@
//!
//! You may also want to check [David Koloski](https://github.com/djkoloski)'s
//! [Rust serialization benchmarks](https://github.com/djkoloski/rust_serialization_benchmark)
//! for help selecting the codec right for your project.
//! for help selecting the codec (i.e. `bincode_1_3`, `rmp_serde_1_3`, etc.)
//! that's best for your project.
#![feature(doc_cfg)]
@@ -26,6 +27,7 @@
feature = "bincode_1_3",
feature = "bincode_2_rc",
feature = "postcard_1_0",
feature = "rmp_serde_1_3",
doc
))]
mod codec;
@@ -35,6 +37,7 @@ mod codec;
feature = "bincode_1_3",
feature = "bincode_2_rc",
feature = "postcard_1_0",
feature = "rmp_serde_1_3",
doc
))]
pub use codec::*;
@@ -118,6 +121,11 @@ pub struct DowngradeError {
/// See examples:
/// - [README.md](https://github.com/vincent-herlemont/native_model) file.
/// - other [examples](https://github.com/vincent-herlemont/native_model/tree/master/tests/example)
///
/// # Errors
///
/// The errors returned from this function depend on the [`Encode`] trait
/// implementor (the serializer), i.e. `bincode_2_rc`.
pub fn encode<T: crate::Model>(model: &T) -> Result<Vec<u8>> {
T::native_model_encode(model)
}
@@ -134,6 +142,11 @@ pub fn encode_downgrade<T: crate::Model>(model: T, version: u32) -> Result<Vec<u
/// See examples:
/// - [README.md](https://github.com/vincent-herlemont/native_model) file.
/// - other [examples](https://github.com/vincent-herlemont/native_model/tree/master/tests/example)
///
/// # Errors
///
/// The errors returned from this function depend on the [`Decode`] trait
/// implementor (the deserializer), i.e. `bincode_2_rc`.
pub fn decode<T: crate::Model>(data: Vec<u8>) -> Result<(T, u32)> {
T::native_model_decode(data)
}
@@ -145,18 +158,11 @@ pub trait Model: Sized {
fn native_model_version_str() -> &'static str;
// --------------- Decode ---------------
fn native_model_decode_body(data: Vec<u8>, id: u32) -> DecodeResult<Self>
where
Self: Sized;
fn native_model_decode_body(data: Vec<u8>, id: u32) -> DecodeResult<Self>;
fn native_model_decode_upgrade_body(data: Vec<u8>, id: u32, version: u32) -> Result<Self>
where
Self: Sized;
fn native_model_decode_upgrade_body(data: Vec<u8>, id: u32, version: u32) -> Result<Self>;
fn native_model_decode(data: Vec<u8>) -> Result<(Self, u32)>
where
Self: Sized,
{
fn native_model_decode(data: Vec<u8>) -> Result<(Self, u32)> {
let native_model = crate::Wrapper::deserialize(&data[..]).unwrap();
let source_id = native_model.get_id();
let source_version = native_model.get_version();
@@ -170,18 +176,11 @@ pub trait Model: Sized {
// --------------- Encode ---------------
fn native_model_encode_body(&self) -> EncodeResult<Vec<u8>>
where
Self: Sized;
fn native_model_encode_body(&self) -> EncodeResult<Vec<u8>>;
fn native_model_encode_downgrade_body(self, version: u32) -> Result<Vec<u8>>
where
Self: Sized;
fn native_model_encode_downgrade_body(self, version: u32) -> Result<Vec<u8>>;
fn native_model_encode(&self) -> Result<Vec<u8>>
where
Self: Sized,
{
fn native_model_encode(&self) -> Result<Vec<u8>> {
let mut data = self.native_model_encode_body()?;
let data = crate::native_model_encode(
&mut data,
@@ -191,10 +190,7 @@ pub trait Model: Sized {
Ok(data)
}
fn native_model_encode_downgrade(self, version: u32) -> Result<Vec<u8>>
where
Self: Sized,
{
fn native_model_encode_downgrade(self, version: u32) -> Result<Vec<u8>> {
let mut data = self.native_model_encode_downgrade_body(version)?;
let data = crate::native_model_encode(&mut data, Self::native_model_id(), version);
Ok(data)
+1 -1
View File
@@ -17,7 +17,7 @@ impl<T: SplitByteSlice> Wrapper<T> {
Some(native_model)
}
pub fn value(&self) -> &T {
pub const fn value(&self) -> &T {
&self.value
}