Skip to content

Commit

Permalink
update document
Browse files Browse the repository at this point in the history
  • Loading branch information
yanganto committed Aug 13, 2024
1 parent eeeaa4a commit 8eac7eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ This crate also includes the following optional features:
- `std`(optional):
- `box`: implements the `Patch<Box<P>>` trait for `T` where `T` implements `Patch<P>`.
This let you patch a boxed (or not) struct with a boxed patch.
- `option`: implements the `Patch<Option<P>>` trait for `Option<T>` where `T` implements `Patch<P>`.
`T` also needs to implement `From<P>`.
This let you patch structs containing fields with optional values.
- `option`: implements the `Patch<Option<P>>` trait for `Option<T>` where `T` implements `Patch<P>`, please take a look at the example to learn more.
- default: `T` needs to implement `From<P>`. When patching on None, it will based on `from<P>` to cast T, and this let you patch structs containing fields with optional values.
- `none_as_default`: `T` needs to implement `Default`. When patching on None, it will patch on a default instance, and this also let you patch structs containing fields with optional values.
- `keep_none`: When patching on None, it is still None.

[crates-badge]: https://img.shields.io/crates/v/struct-patch.svg
[crate-url]: https://crates.io/crates/struct-patch
Expand Down
7 changes: 6 additions & 1 deletion struct-patch/examples/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,17 @@ fn keep_none_feature() {

#[cfg(feature = "option")]
fn main() {
// NOTE:
// The `pure_none_feature` and `none_as_default_feature` are the same logic,
// but the former uses `From` trait and the later uses `Default` trait.
// You can base on your need to use `option` feature or `none_as_default` feature
#[cfg(all(not(feature = "keep_none"), not(feature = "none_as_default")))]
pure_none_feature();

#[cfg(feature = "none_as_default")]
none_as_default_feature();

// NOTE:
// In the feature, the patch do not allow to apply on None
#[cfg(feature = "keep_none")]
keep_none_feature();
}
Expand Down

0 comments on commit 8eac7eb

Please sign in to comment.