Struct ToJSONObject

Source
pub struct ToJSONObject<K, V, I>(pub I)
where
    K: JSONString,
    V: JSONValue,
    for<'a> &'a I: IntoIterator<Item = &'a (K, V)>;
Expand description

A struct used to wrap another type and make it serializable as a json object. The other type has to be able to yield (key, value) pairs by implementing IntoIterator.

§Examples

Serialize a vec as a json object

use json_in_type::object::ToJSONObject;
use json_in_type::JSONValue;

let my_obj = ToJSONObject(vec![("x", 1), ("y", 2)]);

assert_eq!("{\"x\":1,\"y\":2}", my_obj.to_json_string());

Tuple Fields§

§0: I

Trait Implementations§

Source§

impl<K, V, I> JSONValue for ToJSONObject<K, V, I>
where K: JSONString, V: JSONValue, for<'a> &'a I: IntoIterator<Item = &'a (K, V)>,

Source§

fn write_json<W: Write>(&self, w: &mut W) -> Result<()>

Write the object as json to the given writer Read more
Source§

fn to_json_string(&self) -> String

Returns the object formatted as a json string Read more
Source§

fn to_json_buffer(&self) -> Vec<u8>

Returns a buffer containing the bytes of a json representation of the object

Auto Trait Implementations§

§

impl<K, V, I> Freeze for ToJSONObject<K, V, I>
where I: Freeze,

§

impl<K, V, I> RefUnwindSafe for ToJSONObject<K, V, I>
where I: RefUnwindSafe,

§

impl<K, V, I> Send for ToJSONObject<K, V, I>
where I: Send,

§

impl<K, V, I> Sync for ToJSONObject<K, V, I>
where I: Sync,

§

impl<K, V, I> Unpin for ToJSONObject<K, V, I>
where I: Unpin,

§

impl<K, V, I> UnwindSafe for ToJSONObject<K, V, I>
where I: UnwindSafe,

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.