pub struct JsonValueEncoder { /* private fields */ }Expand description
Projects serializable values into strict materialized JSON.
The encoder accepts the full signed and unsigned 64-bit JSON integer range,
rejects wider numeric values and non-finite floats, validates map keys, and
rejects duplicate object keys. It owns no resource budget; use
crate::encode::JsonEncoder when encoded text and resource accounting are
required.
§Examples
use qubit_json::value::JsonValueEncoder;
use serde_json::json;
let encoder = JsonValueEncoder::new();
let value = encoder.encode(&json!({"ok": true}))?;
assert_eq!(value, json!({"ok": true}));Implementations§
Source§impl JsonValueEncoder
impl JsonValueEncoder
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a strict encoder with the default immutable policy.
§Returns
A reusable encoder that performs no resource accounting.
Sourcepub fn encode<T>(&self, value: &T) -> Result<Value, JsonSerializationError>
pub fn encode<T>(&self, value: &T) -> Result<Value, JsonSerializationError>
Projects one serializable value into strict JSON.
§Type Parameters
T- Source type traversed through its Serde representation.
§Parameters
value- Borrowed value to project without taking ownership.
§Returns
The fully materialized JSON value.
§Errors
Returns a strict value error whose precise kind distinguishes number, object-key, RawValue, capacity, serializer-contract, and opaque custom failures without retaining arbitrary diagnostic text.
Trait Implementations§
Source§impl Clone for JsonValueEncoder
impl Clone for JsonValueEncoder
Source§fn clone(&self) -> JsonValueEncoder
fn clone(&self) -> JsonValueEncoder
Returns a duplicate of the value. Read more
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 Copy for JsonValueEncoder
Source§impl Debug for JsonValueEncoder
impl Debug for JsonValueEncoder
Source§impl Default for JsonValueEncoder
impl Default for JsonValueEncoder
Source§fn default() -> JsonValueEncoder
fn default() -> JsonValueEncoder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for JsonValueEncoder
impl RefUnwindSafe for JsonValueEncoder
impl Send for JsonValueEncoder
impl Sync for JsonValueEncoder
impl Unpin for JsonValueEncoder
impl UnsafeUnpin for JsonValueEncoder
impl UnwindSafe for JsonValueEncoder
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