You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+6-57
Original file line number
Diff line number
Diff line change
@@ -39,65 +39,14 @@ fn test_simple_struct() {
39
39
}
40
40
```
41
41
42
-
## Features
42
+
## Docs shortcuts
43
43
44
-
Opting out from Serde allows borsh to have some features that currently are not available for serde-compatible serializers.
45
-
Currently we support two features: `borsh(init=<your initialization method name>` and `borsh(skip)` (the former one not available in Serde).
44
+
Following pages are highlighted here just to give reader a chance at learning that
45
+
they exist.
46
46
47
-
`borsh(init=...)` allows to automatically run an initialization function right after deserialization. This adds a lot of convenience for objects that are architectured to be used as strictly immutable. Usage example:
`borsh(skip)` allows to skip serializing/deserializing fields, assuming they implement `Default` trait, similarly to `#[serde(skip)]`.
69
-
70
-
```rust
71
-
#[derive(BorshSerialize, BorshDeserialize)]
72
-
structA {
73
-
x:u64,
74
-
#[borsh(skip)]
75
-
y:f32,
76
-
}
77
-
```
78
-
79
-
### Enum with explicit discriminant
80
-
81
-
`#[borsh(use_discriminant=false|true])` is required if you have an enum with explicit discriminant. This setting affects `BorshSerialize` and `BorshDeserialize` behaviour at the same time.
82
-
83
-
In the future, borsh will drop the requirement to explicitly use `#[borsh(use_discriminant=false|true)]`, and will default to `true`, but to make sure that the transition from the older versions of borsh (before 0.11 release) does not cause silent breaking changes in de-/serialization, borsh 1.0 will require to specify if the explicit enum discriminant should be used as a de-/serialization tag value.
84
-
85
-
If you don't specify `use_discriminant` option for enum with explicit discriminant, you will get an error:
86
-
87
-
```bash
88
-
error: You have to specify `#[borsh(use_discriminant=true)]` or `#[borsh(use_discriminant=false)]`for all enums with explicit discriminant
89
-
```
90
-
91
-
In order to preserve the behaviour of borsh versions before 0.11, which did not respect explicit enum discriminants for de-/serialization, use `#[borsh(use_discriminant=false)]`, otherwise, use `true`:
0 commit comments