Skip to content

Commit 865fe12

Browse files
author
dj8yf0μl
committed
doc: replace ignore -> rust whereever possible
1 parent e6a09f8 commit 865fe12

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

borsh-derive/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn check_attrs_get_cratename(input: &TokenStream) -> Result<Path, Error> {
3030
cratename::get(&derive_input.attrs)
3131
}
3232

33-
/// moved to documnetation of **Derive Macro** `BorshSerialize` in `borsh` crate
33+
/// moved to docs of **Derive Macro** `BorshSerialize` in `borsh` crate
3434
#[proc_macro_derive(BorshSerialize, attributes(borsh))]
3535
pub fn borsh_serialize(input: TokenStream) -> TokenStream {
3636
let cratename = match check_attrs_get_cratename(&input) {

docs/rustdoc_include/borsh_serialize.md

+53-16
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ struct A<U, V> {
1919
}
2020
```
2121

22-
```ignore
22+
```rust
23+
use borsh::BorshSerialize;
24+
2325
/// impl<U, V> borsh::ser::BorshSerialize for A<U, V>
2426
/// where
2527
/// U: borsh::ser::BorshSerialize,
@@ -60,7 +62,8 @@ Attribute is optional.
6062
6163
Examples of usage:
6264
63-
```ignore
65+
(example is not tested, as there's usually no `reexporter` crate during doc build)
66+
```rust,ignore
6467
use reexporter::borsh::BorshSerialize;
6568
6669
// specifying the attribute removes need for a direct import of `borsh` into `[dependencies]`
@@ -73,7 +76,8 @@ struct B {
7376
}
7477
```
7578
76-
```ignore
79+
(example is not tested, as there's usually no `reexporter` crate during doc build)
80+
```rust,ignore
7781
use reexporter::borsh::{self, BorshSerialize};
7882
7983
// specifying the attribute removes need for a direct import of `borsh` into `[dependencies]`
@@ -93,28 +97,33 @@ This attribute is only applicable to enums.
9397
You must specify `use_discriminant` for all enums with explicit discriminants in your project.
9498
9599
This is equivalent of borsh version 0.10.3 (explicit discriminant is ignored and this enum is equivalent to `A` without explicit discriminant):
96-
```ignore
100+
101+
```rust
102+
# use borsh::BorshSerialize;
103+
#
97104
#[derive(BorshSerialize)]
98105
#[borsh(use_discriminant = false)]
99106
enum A {
100-
A
107+
A,
101108
B = 10,
102109
}
103110
```
104111
105112
To have explicit discriminant value serialized as is, you must specify `borsh(use_discriminant=true)` for enum.
106-
```ignore
113+
```rust
114+
# use borsh::BorshSerialize;
115+
#
107116
#[derive(BorshSerialize)]
108117
#[borsh(use_discriminant = true)]
109118
enum B {
110-
A
119+
A,
111120
B = 10,
112121
}
113122
```
114123
115124
###### borsh, expressions, evaluating to `isize`, as discriminant
116125
This case is not supported:
117-
```ignore
126+
```rust,compile_fail
118127
const fn discrim() -> isize {
119128
0x14
120129
}
@@ -133,7 +142,7 @@ enum X {
133142
134143
###### borsh explicit discriminant does not support literal values outside of u8 range
135144
This is not supported:
136-
```ignore
145+
```rust,compile_fail
137146
#[derive(BorshSerialize)]
138147
#[borsh(use_discriminant = true)]
139148
enum X {
@@ -152,7 +161,9 @@ enum X {
152161
153162
`#[borsh(skip)]` makes derive skip adding any type parameters, present in the field, to parameters bound by `borsh::ser::BorshSerialize`.
154163
155-
```ignore
164+
```rust
165+
# use borsh::BorshSerialize;
166+
#
156167
#[derive(BorshSerialize)]
157168
struct A {
158169
x: u64,
@@ -174,9 +185,15 @@ Attribute adds possibility to override bounds for `BorshSerialize` in order to e
174185
1. removal of bounds on type parameters from struct/enum definition itself and moving them to the trait's implementation block.
175186
2. fixing complex cases, when derive hasn't figured out the right bounds on type parameters automatically.
176187
177-
```ignore
188+
```rust
189+
# use borsh::BorshSerialize;
190+
# #[cfg(feature = "hashbrown")]
191+
# use hashbrown::HashMap;
192+
# #[cfg(feature = "std")]
193+
# use std::collections::HashMap;
178194
/// additional bound `T: Ord` (required by `HashMap`) is injected into
179195
/// derived trait implementation via attribute to avoid adding the bounds on the struct itself
196+
# #[cfg(hash_collections)]
180197
#[derive(BorshSerialize)]
181198
struct A<T, U> {
182199
a: String,
@@ -188,7 +205,12 @@ struct A<T, U> {
188205
```
189206
190207
191-
```ignore
208+
```rust
209+
# use borsh::BorshSerialize;
210+
trait TraitName {
211+
type Associated;
212+
fn method(&self);
213+
}
192214
/// derive here figures the bound erroneously as `T: borsh::ser::BorshSerialize`
193215
#[derive(BorshSerialize)]
194216
struct A<T, V>
@@ -221,12 +243,22 @@ It may be used when `BorshSerialize` cannot be implemented for field's type, if
221243
222244
It may be used to override the implementation of serialization for some other reason.
223245
224-
```ignore
246+
```rust
247+
use borsh::BorshSerialize;
225248
use indexmap::IndexMap;
226249
250+
/// this a stub module, representing a 3rd party crate `indexmap`
251+
mod indexmap {
252+
/// this a stub struct, representing a 3rd party `indexmap::IndexMap`
253+
/// or some local type we want to override trait implementation for
254+
pub struct IndexMap<K, V> {
255+
pub(crate) tuples: Vec<(K, V)>,
256+
}
257+
258+
}
259+
227260
mod index_map_impl {
228-
use super::IndexMap;
229-
use core::hash::Hash;
261+
use super::indexmap::IndexMap;
230262
231263
pub fn serialize_index_map<
232264
K: borsh::ser::BorshSerialize,
@@ -236,7 +268,9 @@ mod index_map_impl {
236268
obj: &IndexMap<K, V>,
237269
writer: &mut W,
238270
) -> ::core::result::Result<(), borsh::io::Error> {
239-
let key_value_tuples = obj.iter().collect::<Vec<_>>();
271+
// the line of implementation for type from real `indexmap` crate
272+
// let key_value_tuples = obj.iter().collect::<Vec<_>>();
273+
let key_value_tuples = obj.tuples.iter().collect::<Vec<_>>();
240274
borsh::BorshSerialize::serialize(&key_value_tuples, writer)?;
241275
Ok(())
242276
}
@@ -250,6 +284,9 @@ struct B<K, V> {
250284
x: IndexMap<K, V>,
251285
y: String,
252286
}
287+
288+
# fn main() {
289+
# }
253290
```
254291
255292
###### usage (comprehensive example)

0 commit comments

Comments
 (0)