[−][src]Enum sj::Value
A value
Usage
Formatting as JSON string
-
To format as compacted JSON string, you can use
to_string()
or implementation ofFrom<Value> for Vec<u8>
. -
To format with default tab width (
4
), you can use#
(viaFormatter
):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:
impl From<...> for Value; impl TryFrom<&Value> for ...; impl TryFrom<Value> for ...;
About TryFrom
implementations:
Variants
String(String)
Number(Number)
Boolean(bool)
Object(Object)
Array(Array)
Methods
impl Value
[src]
pub fn write<W>(&self, stream: &mut W) -> IoResult<()> where
W: Write,
[src]
W: Write,
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]
&self,
tab: Option<usize>,
stream: &mut W
) -> IoResult<()> where
W: Write,
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]
T: Into<Value>,
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.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for bool
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for bool
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for Object
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for Array
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for i8
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for i8
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for i16
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for i16
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for i32
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for i32
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for i64
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for i64
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for i128
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for i128
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for isize
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for isize
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for u8
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for u8
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for u16
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for u16
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for u32
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for u32
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for u64
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for u64
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for u128
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for u128
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for usize
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for usize
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for f32
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for f32
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Value> for f64
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for f64
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Self::Error>
[src]
impl TryFrom<Vec<u8>> for Value
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error>
[src]
impl FromIterator<(String, Value)> for Value
[src]
impl FromIterator<Value> for Value
[src]
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = Value>,
[src]
T: IntoIterator<Item = Value>,
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]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,