1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
mod de;
mod value;
use crate::{stry, Deserializer, Error, ErrorType, Result};
use serde::Deserialize;
use std::fmt;
pub use value::*;
#[cfg_attr(not(feature = "no-inline"), inline(always))]
pub fn from_slice<'a, T>(s: &'a mut [u8]) -> Result<T>
where
T: Deserialize<'a>,
{
let mut deserializer = stry!(Deserializer::from_slice(s));
T::deserialize(&mut deserializer)
}
#[cfg_attr(not(feature = "no-inline"), inline(always))]
pub fn from_str<'a, T>(s: &'a mut str) -> Result<T>
where
T: Deserialize<'a>,
{
let mut deserializer = stry!(Deserializer::from_slice(unsafe { s.as_bytes_mut() }));
T::deserialize(&mut deserializer)
}
impl std::error::Error for Error {}
impl serde::de::Error for Error {
fn custom<T: fmt::Display>(msg: T) -> Self {
Error::generic(ErrorType::Serde(msg.to_string()))
}
}
impl serde_ext::ser::Error for Error {
fn custom<T: fmt::Display>(msg: T) -> Self {
Error::generic(ErrorType::Serde(msg.to_string()))
}
}