pub enum TjsonValue {
Null,
Bool(bool),
Number(Number),
String(String),
Array(Vec<TjsonValue>),
Object(Vec<(String, TjsonValue)>),
}Expand description
A parsed TJSON value. Mirrors the JSON type system with the same six variants.
Numbers are stored as strings to preserve exact representation. Objects are stored as
an ordered Vec of key-value pairs, which allows duplicate keys at the data structure
level (though JSON and TJSON parsers typically deduplicate them).
Variants§
Null
JSON null.
Bool(bool)
JSON boolean.
Number(Number)
JSON number.
String(String)
JSON string.
Array(Vec<TjsonValue>)
JSON array.
Object(Vec<(String, TjsonValue)>)
JSON object, as an ordered list of key-value pairs.
Implementations§
Source§impl TjsonValue
impl TjsonValue
Sourcepub fn to_tjson_with(&self, options: TjsonOptions) -> Result<String>
pub fn to_tjson_with(&self, options: TjsonOptions) -> Result<String>
Render this value as a TJSON string using the given options.
Currently this is effectively infallible in practice — when options conflict or
content cannot be laid out ideally (e.g. wrap_width too narrow with folding
disabled), the renderer overflows rather than failing. The Result return type
is intentional and forward-looking: a future option like fail_on_overflow
could request strict layout enforcement and return an error rather than overflowing.
Keeping Result here avoids a breaking API change when that option is added.
At that point Error would likely gain a dedicated variant for layout constraint
failures, distinct from the existing Error::Render (malformed data).
Sourcepub fn to_json(&self) -> Result<JsonValue, Error>
pub fn to_json(&self) -> Result<JsonValue, Error>
Convert this value to a serde_json::Value. If the value contains duplicate object keys,
only the last value for each key is kept (serde_json maps deduplicate on insert).
use tjson::TjsonValue;
let json: serde_json::Value = serde_json::json!({"name": "Alice"});
let tjson = TjsonValue::from(json.clone());
assert_eq!(tjson.to_json().unwrap(), json);Trait Implementations§
Source§impl Clone for TjsonValue
impl Clone for TjsonValue
Source§fn clone(&self) -> TjsonValue
fn clone(&self) -> TjsonValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TjsonValue
impl Debug for TjsonValue
Source§impl Display for TjsonValue
impl Display for TjsonValue
Source§impl From<Value> for TjsonValue
impl From<Value> for TjsonValue
Source§impl FromStr for TjsonValue
let v: tjson::TjsonValue = " name: Alice".parse().unwrap();
assert!(matches!(v, tjson::TjsonValue::Object(_)));
impl FromStr for TjsonValue
let v: tjson::TjsonValue = " name: Alice".parse().unwrap();
assert!(matches!(v, tjson::TjsonValue::Object(_)));Source§impl PartialEq for TjsonValue
impl PartialEq for TjsonValue
Source§impl Serialize for TjsonValue
impl Serialize for TjsonValue
impl Eq for TjsonValue
impl StructuralPartialEq for TjsonValue
Auto Trait Implementations§
impl Freeze for TjsonValue
impl RefUnwindSafe for TjsonValue
impl Send for TjsonValue
impl Sync for TjsonValue
impl Unpin for TjsonValue
impl UnsafeUnpin for TjsonValue
impl UnwindSafe for TjsonValue
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.