serde-scale-wrap

Crates.ioserde-scale-wrap
lib.rsserde-scale-wrap
version0.3.0
sourcesrc
created_at2020-10-08 07:33:13.195568
updated_at2021-07-02 06:42:00.784871
descriptionWrapper for types implementing `Serialize`/`Deserialize` to implement `Encode`/`Decode` automatically
homepagehttps://github.com/stephaneyfx/serde-scale-wrap
repositoryhttps://github.com/stephaneyfx/serde-scale-wrap.git
max_upload_size
id297176
size10,810
crate-publishers (github:osmosis-labs:crate-publishers)

documentation

README

Overview

Wrapper for types implementing Serialize/Deserialize to implement Encode/Decode automatically.

Example

extern crate alloc;

use alloc::string::String;
use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};
use serde_scale_wrap::Wrap;

#[derive(Debug, Deserialize, PartialEq, Serialize)]
struct Foo {
    x: i32,
    s: String,
}

let original = Foo { x: 3, s: "foo".into() };
let serialized = Wrap(&original).encode();
let Wrap(deserialized) = Wrap::<Foo>::decode(&mut &*serialized).unwrap();
assert_eq!(original, deserialized);

Conformance

âš  Option<bool> is serialized as a single byte according to the SCALE encoding, which differs from the result of Encode::encode -- Encode expects OptionBool to be used instead.

Features

no_std is supported by disabling default features.

  • std: Support for std. It is enabled by default.

🔖 Features enabled in build dependencies and proc-macros are also enabled for normal dependencies, which may cause serde to have its std feature on when it is not desired. Nightly cargo prevents this from happening with -Z features=host_dep or the following in .cargo/config:

[unstable]
features = ["host_dep"]

For example, this issue arises when depending on parity-scale-codec-derive.

Contribute

All contributions shall be licensed under the zlib license.

Related projects

Commit count: 9

cargo fmt