[][src]Enum sj::Value

pub enum Value {
    String(String),
    Number(Number),
    Boolean(bool),
    Null,
    Object(Object),
    Array(Array),
}

A value

Usage

Formatting as JSON string

  • To format as compacted JSON string, you can use to_string() or implementation of From<Value> for Vec<u8>.

  • To format with default tab width (4), you can use # (via Formatter):

    format!(
        "{:#}",
        sj::parse(&mut &br#"["test"]"#[..]).unwrap(),
    );
  • You can set tab width (required) and tab level (optional):

    format!(
        "{:width$.level$}",
        sj::parse(&mut &br#"["test"]"#[..]).unwrap(),
        width=4, level=0,
    );

Writing as JSON string to Write

Can be done via write() or write_nicely().

Converting Rust types to Value and vice versa

There are some implementations:

This example is not tested
impl From<...> for Value;
impl TryFrom<&Value> for ...;
impl TryFrom<Value> for ...;

About TryFrom implementations:

  • For primitives, since they're cheap, they have implementations on either a borrowed or an owned value.
  • For collections such as String, Vec..., they only have implementations on an owned value. So data is moved, not copied.

Variants

String(String)
Number(Number)
Boolean(bool)
Null
Object(Object)
Array(Array)

Methods

impl Value[src]

pub fn write<W>(&self, stream: &mut W) -> IoResult<()> where
    W: Write
[src]

Writes this value as compacted JSON string to a stream

Notes

  • The stream is used as-is. For better performance, you should wrap your stream inside a BufWriter.
  • This function does not flush the stream when done.

pub fn write_nicely<W>(
    &self,
    tab: Option<usize>,
    stream: &mut W
) -> IoResult<()> where
    W: Write
[src]

Writes this value as nicely formatted JSON string to a stream

Notes

  • If you don't provide tab size, default (4) will be used.
  • The stream is used as-is. For better performance, you should wrap your stream inside a BufWriter.
  • This function does not flush the stream when done.

Trait Implementations

impl From<String> for Value[src]

impl From<Number> for Value[src]

impl From<bool> for Value[src]

impl From<BTreeMap<String, Value>> for Value[src]

impl From<Vec<Value>> for Value[src]

impl<T> From<Option<T>> for Value where
    T: Into<Value>, 
[src]

impl From<i8> for Value[src]

impl From<i16> for Value[src]

impl From<i32> for Value[src]

impl From<i64> for Value[src]

impl From<i128> for Value[src]

impl From<isize> for Value[src]

impl From<u8> for Value[src]

impl From<u16> for Value[src]

impl From<u32> for Value[src]

impl From<u64> for Value[src]

impl From<u128> for Value[src]

impl From<usize> for Value[src]

impl From<f32> for Value[src]

impl From<f64> for Value[src]

impl From<Value> for Vec<u8>[src]

impl Debug for Value[src]

impl Display for Value[src]

impl TryFrom<Value> for String[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for bool[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for bool[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for Object[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for Array[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for i8[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for i8[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for i16[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for i16[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for i32[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for i32[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for i64[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for i64[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for i128[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for i128[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for isize[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for isize[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for u8[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for u8[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for u16[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for u16[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for u32[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for u32[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for u64[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for u64[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for u128[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for u128[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for usize[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for usize[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for f32[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for f32[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ Value> for f64[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for f64[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Vec<u8>> for Value[src]

type Error = Error

The type returned in the event of a conversion error.

impl FromIterator<(String, Value)> for Value[src]

impl FromIterator<Value> for Value[src]

Auto Trait Implementations

impl Unpin for Value

impl Send for Value

impl Sync for Value

impl UnwindSafe for Value

impl RefUnwindSafe for Value

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]