pub struct String<'json, 'p> { /* private fields */ }
Expand description
A JSON string.
Implementations§
Source§impl<'json, 'p> String<'json, 'p>
impl<'json, 'p> String<'json, 'p>
Sourcepub fn get(&mut self) -> Result<ParsedString<'json>, ParseStringError>
pub fn get(&mut self) -> Result<ParsedString<'json>, ParseStringError>
Try to parse the string. Note that escape sequences will not be evaluated!
§Errors
If parsing the string fails, this will return a ParseStringError
.
Examples found in repository?
examples/format.rs (line 30)
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match &mut *self.0.borrow_mut() {
29 Any::String(string) => {
30 let parsed = string.get().expect("failed to parse string");
31 let raw = parsed.unescaped();
32 write!(f, "{raw:?}")
33 }
34
35 Any::Number(number) => {
36 let parsed = number.get().expect("failed to parse number");
37 <number::ParsedNumber as fmt::Display>::fmt(&parsed, f)
38 }
39
40 Any::Object(object) => {
41 let mut map = f.debug_map();
42
43 while let Some((key, value)) = object.next().expect("failed to parse an object") {
44 let raw_key = key.unescaped();
45 map.entry(&raw_key, &Format(RefCell::new(value)));
46 }
47
48 map.finish()
49 }
50
51 Any::Array(array) => {
52 let mut list = f.debug_list();
53
54 while let Some(value) = array.next().expect("failed to parse an array") {
55 list.entry(&Format(RefCell::new(value)));
56 }
57
58 list.finish()
59 }
60
61 Any::Literal(literal) => {
62 let parsed = literal.get().expect("failed to parse literal");
63 <literal::ParsedLiteral as fmt::Display>::fmt(&parsed, f)
64 }
65 }
66 }
Sourcepub fn finish(&mut self) -> Result<(), ParseStringError>
pub fn finish(&mut self) -> Result<(), ParseStringError>
Finish parsing the string so that the parent can continue.
If Self::get
has been called, this is not needed.
§Errors
If parsing fails in this string, the error is returned as a ParseStringError
.
Trait Implementations§
Auto Trait Implementations§
impl<'json, 'p> Freeze for String<'json, 'p>
impl<'json, 'p> !RefUnwindSafe for String<'json, 'p>
impl<'json, 'p> !Send for String<'json, 'p>
impl<'json, 'p> !Sync for String<'json, 'p>
impl<'json, 'p> Unpin for String<'json, 'p>
impl<'json, 'p> !UnwindSafe for String<'json, 'p>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more