- Just a wrapper of Serde and 100% compatible
- Declarative validation in deserialization by
#[serde(validate = "...")]
Example
[]
= "0.2"
= "1.0"
use ;
Of course, you can use it in combination with some validation tools like validator! ( full example )
Attribute
-
#[serde(validate = "function")]
Automatically validate by the
function
in deserialization. Thefunction
must be callable asfn(&self) -> Result<(), impl Display>
.
Errors are converted to aString
internally and passed toserde::de::Error::custom
. -
#[serde(validate(by = "function", error = "Type"))]
Using given
Type
for validation error without internal conversion. Thefunction
must explicitly returnResult<(), Type>
.
This may be preferred when you need better performance even in error cases.
For no-std use, this is the only way supported.
Both "function"
and "Type"
accept path like "crate::util::validate"
.
Additionally, #[serdev(crate = "path::to::serdev")]
is supported for reexport from another crate.
License
Licensed under MIT LICENSE ( LICENSE or https://opensource.org/licenses/MIT ).