pub struct JsonBytesValueEncoder<T> { /* private fields */ }Expand description
Encodes one serializable value into UTF-8 JSON bytes via serde_json.
Its stateless marker implements Clone, Copy, and Default without
requiring those traits on T.
§Type Parameters
T: Source value type serialized through Serde.
§Examples
use qubit_codec::JsonBytesValueEncoder;
use qubit_codec::ValueEncoder;
use serde::Serialize;
#[derive(Serialize)]
struct Point {
x: i32,
y: i32,
}
let mut encoder = JsonBytesValueEncoder::<Point>::new();
let json = encoder.encode(&Point { x: 1, y: 2 }).unwrap();
assert_eq!(json, br#"{"x":1,"y":2}"#);Implementations§
Trait Implementations§
Source§impl<T> Clone for JsonBytesValueEncoder<T>
impl<T> Clone for JsonBytesValueEncoder<T>
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Returns the same stateless encoder marker without constructing or
cloning a value of type T.
This implementation does not require T: Clone.
§Returns
Returns a copy of this encoder.
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<T> Copy for JsonBytesValueEncoder<T>
Source§impl<T: Debug> Debug for JsonBytesValueEncoder<T>
impl<T: Debug> Debug for JsonBytesValueEncoder<T>
Source§impl<T> Default for JsonBytesValueEncoder<T>
impl<T> Default for JsonBytesValueEncoder<T>
Source§impl<T> ValueEncoder<T> for JsonBytesValueEncoder<T>where
T: Serialize,
impl<T> ValueEncoder<T> for JsonBytesValueEncoder<T>where
T: Serialize,
Source§fn encode(&mut self, input: &T) -> Result<Self::Output, Self::Error>
fn encode(&mut self, input: &T) -> Result<Self::Output, Self::Error>
Serializes input into UTF-8 JSON bytes.
§Parameters
input: Value borrowed for the duration of serialization.
§Returns
Returns a newly allocated vector containing the serialized JSON.
§Errors
Returns a JSON error if T rejects serialization or contains a map key
that cannot be represented as a JSON object key.
Auto Trait Implementations§
impl<T> Forget for JsonBytesValueEncoder<T>
impl<T> Freeze for JsonBytesValueEncoder<T>where
PhantomData<T>: Freeze,
impl<T> RefUnwindSafe for JsonBytesValueEncoder<T>where
PhantomData<T>: RefUnwindSafe,
impl<T> Send for JsonBytesValueEncoder<T>where
PhantomData<T>: Send,
impl<T> Sync for JsonBytesValueEncoder<T>where
PhantomData<T>: Sync,
impl<T> Unpin for JsonBytesValueEncoder<T>where
PhantomData<T>: Unpin,
impl<T> UnsafeUnpin for JsonBytesValueEncoder<T>where
PhantomData<T>: UnsafeUnpin,
impl<T> UnwindSafe for JsonBytesValueEncoder<T>where
PhantomData<T>: UnwindSafe,
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