simd_json_derive/impls/
string.rs1use crate::{de, BaseGenerator, Deserialize, DummyGenerator, Result, Serialize, Tape, Write};
2
3impl Serialize for String {
4 #[inline]
5 fn json_write<W>(&self, writer: &mut W) -> Result
6 where
7 W: Write,
8 {
9 DummyGenerator(writer).write_string(self)
10 }
11}
12
13impl<'input> Deserialize<'input> for String {
14 #[inline]
15 fn from_tape(tape: &mut Tape<'input>) -> de::Result<Self>
16 where
17 Self: Sized + 'input,
18 {
19 match tape.next() {
20 Some(simd_json::Node::String(s)) => Ok(String::from(s)),
21 _ => Err(de::Error::expected_string()),
22 }
23 }
24}
25
26impl<'input> Deserialize<'input> for &'input str {
27 #[inline]
28 fn from_tape(tape: &mut Tape<'input>) -> de::Result<Self>
29 where
30 Self: Sized + 'input,
31 {
32 match tape.next() {
33 Some(simd_json::Node::String(s)) => Ok(s),
34 _ => Err(de::Error::expected_string()),
35 }
36 }
37}
38
39impl Serialize for str {
40 #[inline]
41 fn json_write<W>(&self, writer: &mut W) -> Result
42 where
43 W: Write,
44 {
45 DummyGenerator(writer).write_string(self)
46 }
47}
48
49impl<'input> Deserialize<'input> for Box<str> {
72 fn from_tape(tape: &mut Tape<'input>) -> de::Result<Self>
73 where
74 Self: Sized + 'input,
75 {
76 match tape.next() {
77 Some(simd_json::Node::String(s)) => Ok(Box::from(s)),
78 _ => Err(de::Error::expected_string()),
79 }
80 }
81}