Skip to content

Commit

Permalink
wip: PackedLayout doc. fixs use-ink#637.
Browse files Browse the repository at this point in the history
  • Loading branch information
hychen committed Feb 26, 2021
1 parent 4057721 commit 754c901
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/storage/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ proc-macro2 = "1.0"
synstructure = "0.12.4"

[dev-dependencies]
scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
ink_env = { version = "3.0.0-rc2", path = "../../env" }
ink_primitives = { version = "3.0.0-rc2", path = "../../primitives" }
ink_metadata = { version = "3.0.0-rc2", path = "../../metadata" }
Expand Down
30 changes: 30 additions & 0 deletions crates/storage/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,36 @@ synstructure::decl_derive!(
synstructure::decl_derive!(
[PackedLayout] =>
/// Derives `ink_storage`'s `PackedLayout` trait for the given `struct` or `enum`.
///
/// # Examples
/// ```
/// use scale::{Encode, Decode};
/// use ink_primitives::Key;
/// use ink_storage::traits::{
/// SpreadLayout,
/// PackedLayout,
/// push_packed_root,
/// pull_packed_root
/// };
///
/// # ink_env::test::run_test::<ink_env::DefaultEnvironment, _>(|_| {
/// #[derive(Encode, Decode, SpreadLayout, PackedLayout)]
/// struct NamedFields {
/// a: u32,
/// b: [u32; 32],
/// }
///
/// let mut value = NamedFields {
/// a: 123,
/// b: [22; 32],
/// };
///
/// push_packed_root(&value, &mut Key::from([0x42; 32]));
/// let value2: NamedFields = pull_packed_root(&mut Key::from([0x42; 32]));
/// assert_eq!(value.a, value2.a);
/// # Ok(())
/// # });
/// ```
packed_layout_derive
);
synstructure::decl_derive!(
Expand Down

0 comments on commit 754c901

Please sign in to comment.