mirror of
https://github.com/Drop-OSS/native_model.git
synced 2026-01-30 20:55:19 +01:00
docs: moved notes on codecs to README.md
This commit is contained in:
committed by
Vincent Herlemont
parent
24201e59c3
commit
6004a6fbd7
47
README.md
47
README.md
@@ -134,6 +134,53 @@ struct Cord {
|
||||
// Implement the conversion between versions From<DotV2> for DotV3 and From<DotV3> for DotV2.
|
||||
```
|
||||
|
||||
## Codecs
|
||||
|
||||
`native_model` comes with several optional built-in serializer features available:
|
||||
|
||||
- [bincode 1.3](https://crates.io/crates/bincode/1.3.3)
|
||||
- This is the default codec.
|
||||
- **Warning: This codec may not work with all serde-derived types.**
|
||||
|
||||
- [bincode 2.0.0-rc.3](https://crates.io/crates/bincode/2.0.0-rc.3)
|
||||
- Enable the `bincode_2_rc` feature and use the `native_model::bincode_2_rc::Bincode` attribute to have `native_db` use this crate for serializing & deserializing.
|
||||
- **Warning: This codec may not work with all serde-derived types.**
|
||||
|
||||
- [postcard 1.0](https://crates.io/crates/postcard/1.0.8)
|
||||
- Enable the `postcard_1_0` feature and use the `native_model::postcard_1_0::PostCard` attribute.
|
||||
- **Warning: This codec may not work with all serde-derived types.**
|
||||
|
||||
- [rmp-serde 1.3](https://crates.io/crates/rmp-serde/1.3.0)
|
||||
- Enable the `rmp_serde_1_3` feature and use the `native_model::rmp_serde_1_3::RmpSerde` attribute.
|
||||
|
||||
###### Codec example:
|
||||
|
||||
As example, to use `rmp-serde`:
|
||||
|
||||
1. In your project's `Cargo.toml` file, enable the `rmp_serde_1_3` feature for the `native_model` dependency.
|
||||
- Be sure to check `crates.io` for the most recent [`native_model`](https://crates.io/crates/native_model) version number.
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = [ "derive" ] }
|
||||
native_model = { version = "0.4", features = [ "rmp_serde_1_3" ] }
|
||||
```
|
||||
|
||||
2. Assign the `rmp_serde_1_3` codec to your `struct` using the `with` attribute:
|
||||
|
||||
```rust
|
||||
#[derive(Clone, Default, serde::Deserialize, serde::Serialize)]
|
||||
#[native_model(id = 1, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
||||
struct MyStruct {
|
||||
my_string: String,
|
||||
// etc.
|
||||
}
|
||||
```
|
||||
|
||||
###### Additional reading
|
||||
|
||||
You may also want to check out [David Koloski](https://github.com/djkoloski)'s [Rust serialization benchmarks](https://github.com/djkoloski/rust_serialization_benchmark) for help selecting the codec (i.e. `bincode_1_3`, `rmp_serde_1_3`, etc.) that's best for your project.
|
||||
|
||||
## Status
|
||||
|
||||
Early development. Not ready for production.
|
||||
|
||||
59
src/lib.rs
59
src/lib.rs
@@ -14,65 +14,6 @@
|
||||
//! - The crate is in early development, and performance is expected to improve over time.
|
||||
//!
|
||||
//! See examples in the [README.md](https://github.com/vincent-herlemont/native_model) file.
|
||||
//!
|
||||
//! # Codecs
|
||||
//!
|
||||
//! `native_model` comes with several optional built-in serializer features
|
||||
//! available:
|
||||
//!
|
||||
//! - [bincode 1.3](https://crates.io/crates/bincode/1.3.3) · This is the
|
||||
//! default codec. **Warning: This codec may not work with all serde-derived
|
||||
//! types.**
|
||||
//!
|
||||
//! - [bincode 2.0.0-rc.3](https://crates.io/crates/bincode/2.0.0-rc.3) ·
|
||||
//! Enable the `bincode_2_rc` feature and use the
|
||||
//! `native_model::bincode_2_rc::Bincode` attribute to have `native_db` use this
|
||||
//! crate for serializing & deserializing. **Warning: This codec may not work
|
||||
//! with all serde-derived types.**
|
||||
//!
|
||||
//! - [postcard 1.0](https://crates.io/crates/postcard/1.0.8) ·
|
||||
//! Enable the `postcard_1_0` feature and use the
|
||||
//! `native_model::postcard_1_0::PostCard` attribute. **Warning: This codec may
|
||||
//! not work with all serde-derived types.**
|
||||
//!
|
||||
//! - [rmp-serde 1.3](https://crates.io/crates/rmp-serde/1.3.0) ·
|
||||
//! Enable the `rmp_serde_1_3` feature and use the
|
||||
//! `native_model::rmp_serde_1_3::RmpSerde` attribute.
|
||||
//!
|
||||
//! ###### Codec example:
|
||||
//!
|
||||
//! As example, to use `rmp-serde`:
|
||||
//!
|
||||
//! 1. In your project's `Cargo.toml` file, enable the `rmp_serde_1_3` feature
|
||||
//! for the `native_model` dependency. Be sure to check `crates.io` for the most
|
||||
//! recent [`native_model`](https://crates.io/crates/native_model) version
|
||||
//! number.
|
||||
//!
|
||||
//! ```toml
|
||||
//! [dependencies]
|
||||
//! serde = { version = "1.0", features = [ "derive" ] }
|
||||
//! native_model = { version = "0.4", features = [ "rmp_serde_1_3" ] }
|
||||
//! ```
|
||||
//!
|
||||
//! 2. Assign the `rmp_serde_1_3` codec to your `struct` using the `with`
|
||||
//! attribute:
|
||||
//!
|
||||
//! ```rust
|
||||
//! #[derive(Clone, Default, serde::Deserialize, serde::Serialize)]
|
||||
//! #[native_model(id = 1, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
||||
//! struct MyStruct {
|
||||
//! my_string: String,
|
||||
//! // etc.
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! ###### Additional reading
|
||||
//!
|
||||
//! You may also want to check out
|
||||
//! [David Koloski](https://github.com/djkoloski)'s
|
||||
//! [Rust serialization benchmarks](https://github.com/djkoloski/rust_serialization_benchmark)
|
||||
//! for help selecting the codec (i.e. `bincode_1_3`, `rmp_serde_1_3`, etc.)
|
||||
//! that's best for your project.
|
||||
|
||||
#[cfg(any(
|
||||
feature = "serde",
|
||||
|
||||
Reference in New Issue
Block a user