Skip to content

Commit

Permalink
chore: update README (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanarus authored Aug 31, 2024
1 parent 0fa38e6 commit e0bda48
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<br>

- Just a wrapper of serde, serde_derive and 100% compatible
- Validation on deserializing with `#[serde(validate = "...")]`
- Auto validation in deserialization by `#[serde(validate = "...")]`

<div align="right">
<a href="https://github.com/ohkami-rs/serdev/blob/main/LICENSE" target="_blank">
Expand All @@ -22,7 +22,6 @@

<br>


## Example

```toml
Expand Down Expand Up @@ -67,17 +66,19 @@ fn main() {
}
```

Of course, you can use it in combination with some validation tools like <a href="https://crates.io/crates/validator" target="_blank">validator</a>! ( <a href="https://github.com/ohkami-rs/serdev/blob/main/examples/examples/validator.rs" target="_blank">full example</a> )


## Attribute

- `#[serde(validate = "function")]`

Perform validation by the function just after deserializing finished. The function must be callable as `fn(&self) -> Result<(), impl Display>`.\
Perform validation by the function just after deserializing finished. The `function` must be callable as `fn(&self) -> Result<(), impl Display>`.\
Currently, errors are converted to `String` internally and passed to `serde::de::Error::custom`.

- `#[serde(validate(by = "function", error = "Type"))]`

Use given `Type` for validation error without internal conversion. The function must explicitly return `Result<(), Type>`.\
Using given `Type` for validation error without internal conversion. The `function` must explicitly return `Result<(), Type>`.\
This may be preferred when you need better performance _even in error cases_.\
For **no-std** use, this is the only way supported.

Expand All @@ -86,4 +87,4 @@ Both `"function"` and `"Type"` accept path like `"crate::utils::validate"`.

## License

Licensed under MIT LICENSE ( [LICENSE](https://github.com/ohkami-rs/serdev/blob/main/LICENSE) or [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT) ).
Licensed under MIT LICENSE ( [LICENSE](https://github.com/ohkami-rs/serdev/blob/main/LICENSE) or [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT) ).

0 comments on commit e0bda48

Please sign in to comment.