Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(rlp): move example to README.md #177

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/dyn-abi/benches/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn sol_types_encode(c: &mut Criterion) {

g.bench_function("struct", |b| {
let input = encode_struct_input();
b.iter(|| Input::encode(&input));
b.iter(|| Input::encode(black_box(&input)));
});

g.finish();
Expand Down
24 changes: 24 additions & 0 deletions crates/rlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ We strongly recommend deriving RLP traits via the `RlpEncodable` and

Trait methods can then be accessed via the `Encodable` and `Decodable` traits.

## Example

```rust
# #[cfg(feature = "derive")] {
use alloy_rlp::{RlpEncodable, RlpDecodable, Decodable, Encodable};

#[derive(Debug, RlpEncodable, RlpDecodable, PartialEq)]
pub struct MyStruct {
pub a: u64,
pub b: Vec<u8>,
}

let my_struct = MyStruct {
a: 42,
b: vec![1, 2, 3],
};

let mut buffer = Vec::<u8>::new();
let encoded = my_struct.encode(&mut buffer);
let decoded = MyStruct::decode(&mut buffer.as_slice()).unwrap();
assert_eq!(my_struct, decoded);
# }
```

## Provenance note

This crate was originally part of the [reth] project, as [`reth_rlp`].
Expand Down
30 changes: 0 additions & 30 deletions crates/rlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,6 @@
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
)]
// This doctest uses derive, so it cannot be in the README :(
#![cfg_attr(
feature = "derive",
doc = r##"

## Usage Example

```rust
use alloy_rlp::{RlpEncodable, RlpDecodable, Decodable, Encodable};

#[derive(Debug, RlpEncodable, RlpDecodable, PartialEq)]
pub struct MyStruct {
pub a: u64,
pub b: Vec<u8>,
}

fn main() {
let my_struct = MyStruct {
a: 42,
b: vec![1, 2, 3],
};

let mut buffer = Vec::<u8>::new();
let encoded = my_struct.encode(&mut buffer);
let decoded = MyStruct::decode(&mut buffer.as_slice()).unwrap();
assert_eq!(my_struct, decoded);
}
```
"##
)]
#![warn(
missing_docs,
unreachable_pub,
Expand Down