Skip to content

Commit

Permalink
fix: Remove skeptic
Browse files Browse the repository at this point in the history
It is unmaintained and fails to build tests.

Same as vincent-herlemont/native_db#286.
  • Loading branch information
lu-zero authored and vincent-herlemont committed Nov 14, 2024
1 parent 8973ac3 commit 36e1706
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 141 deletions.
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "A thin wrapper around serialized data which add information of id
license = "MIT"
repository = "https://github.com/vincent-herlemont/native_model"
readme = "README.md"
build = "build.rs"
keywords = ["serialization", "interoperability", "data-consistency", "flexibility", "performance"]
categories = ["data-structures", "encoding", "rust-patterns"]
rust-version = "1.73.0"
Expand All @@ -26,18 +25,15 @@ bincode_1_3 = { package = "bincode", version = "1.3.3", optional = true }
bincode_2_rc = { package = "bincode", version = "2.0.0-rc.3", features = ["serde"], optional = true }
postcard_1_0 = { package = "postcard", version = "1.0.8", features = ["alloc"], optional = true }
rmp_serde_1_3 = { package = "rmp-serde", version = "1.3", optional = true }
doc-comment = "0.3.3"

[dev-dependencies]
serde_json = "1.0.116"
criterion = { version = "0.5.1" }
skeptic = "0.13.7"

[features]
default = ["serde", "bincode_1_3"]

[[bench]]
name = "overhead"
harness = false

[build-dependencies]
skeptic = "0.13.7"
84 changes: 79 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ See [concepts](#concepts) for more details.

## Usage

```
```text
Application 1 (DotV1) Application 2 (DotV1 and DotV2)
| |
Encode DotV1 |--------------------------------> | Decode DotV1 to DotV2
Expand All @@ -29,7 +29,38 @@ See [concepts](#concepts) for more details.
```


```rust,skt-main
```rust
use native_model::native_model;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, PartialEq, Debug)]
#[native_model(id = 1, version = 1)]
struct DotV1(u32, u32);

#[derive(Deserialize, Serialize, PartialEq, Debug)]
#[native_model(id = 1, version = 2, from = DotV1)]
struct DotV2 {
name: String,
x: u64,
y: u64,
}

impl From<DotV1> for DotV2 {
fn from(dot: DotV1) -> Self {
DotV2 {
name: "".to_string(),
x: dot.0 as u64,
y: dot.1 as u64,
}
}
}

impl From<DotV2> for DotV1 {
fn from(dot: DotV2) -> Self {
DotV1(dot.x as u32, dot.y as u32)
}
}

// Application 1
let dot = DotV1(1, 2);
let bytes = native_model::encode(&dot).unwrap();
Expand All @@ -54,7 +85,7 @@ let bytes = native_model::encode_downgrade(dot, source_version).unwrap();
// Application 1
let (dot, _) = native_model::decode::<DotV1>(bytes).unwrap();
assert_eq!(dot, DotV1(5, 2));
```
```

- Full example [here](./tests_crate/tests/example/example_main.rs).

Expand Down Expand Up @@ -121,8 +152,9 @@ Attributes:
- `type`: The previous version of the model that you use for the TryFrom implementation.
- `error`: The error type that you use for the TryFrom implementation.

```rust,skt-define-models
```rust
use native_model::native_model;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, PartialEq, Debug)]
#[native_model(id = 1, version = 1)]
Expand All @@ -138,6 +170,22 @@ struct DotV2 {

// Implement the conversion between versions From<DotV1> for DotV2 and From<DotV2> for DotV1.

impl From<DotV1> for DotV2 {
fn from(dot: DotV1) -> Self {
DotV2 {
name: "".to_string(),
x: dot.0 as u64,
y: dot.1 as u64,
}
}
}

impl From<DotV2> for DotV1 {
fn from(dot: DotV2) -> Self {
DotV1(dot.x as u32, dot.y as u32)
}
}

#[derive(Deserialize, Serialize, PartialEq, Debug)]
#[native_model(id = 1, version = 3, try_from = (DotV2, anyhow::Error))]
struct DotV3 {
Expand All @@ -152,6 +200,30 @@ struct Cord {
}

// Implement the conversion between versions From<DotV2> for DotV3 and From<DotV3> for DotV2.

impl TryFrom<DotV2> for DotV3 {
type Error = anyhow::Error;

fn try_from(dot: DotV2) -> Result<Self, Self::Error> {
Ok(DotV3 {
name: dot.name,
cord: Cord { x: dot.x, y: dot.y },
})
}
}

impl TryFrom<DotV3> for DotV2 {
type Error = anyhow::Error;

fn try_from(dot: DotV3) -> Result<Self, Self::Error> {
Ok(DotV2 {
name: dot.name,
x: dot.cord.x,
y: dot.cord.y,
})
}
}

```

## Codecs
Expand Down Expand Up @@ -189,6 +261,8 @@ 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
use native_model::native_model;

#[derive(Clone, Default, serde::Deserialize, serde::Serialize)]
#[native_model(id = 1, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
struct MyStruct {
Expand Down Expand Up @@ -220,7 +294,7 @@ In order to understand how the native model works, you need to understand the fo

Under the hood, the native model is a thin wrapper around serialized data. The `id` and the `version` are twice encoded with a [`little_endian::U32`](https://docs.rs/zerocopy/latest/zerocopy/byteorder/little_endian/type.U32.html). That represents 8 bytes, that are added at the beginning of the data.

```
``` text
+------------------+------------------+------------------------------------+
| ID (4 bytes) | Version (4 bytes)| Data (indeterminate-length bytes) |
+------------------+------------------+------------------------------------+
Expand Down
119 changes: 0 additions & 119 deletions README.md.skt.md

This file was deleted.

11 changes: 0 additions & 11 deletions build.rs

This file was deleted.

9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
//!
//! See examples in the [README.md](https://github.com/vincent-herlemont/native_model) file.
#[cfg(doctest)]
#[macro_use]
extern crate doc_comment;

#[cfg(doctest)]
doc_comment! {
include_str!("../README.md")
}

#[cfg(any(
feature = "serde",
feature = "bincode_1_3",
Expand Down
1 change: 0 additions & 1 deletion tests/skeptic.rs

This file was deleted.

0 comments on commit 36e1706

Please sign in to comment.