Struct String

Source
pub struct String<'json, 'p> { /* private fields */ }
Expand description

A JSON string.

Implementations§

Source§

impl<'json, 'p> String<'json, 'p>

Source

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    }
Source

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§

Source§

impl<'json, 'p> Debug for String<'json, 'p>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.