pub struct JSON(/* private fields */);Expand description
A CBOR-tagged container for UTF-8 JSON text.
The JSON type wraps UTF-8 JSON text as a CBOR byte string with tag 262.
This allows JSON data to be embedded within CBOR structures while
maintaining type information through the tag.
This implementation does not validate that the contained data is well-formed JSON. It simply provides a type-safe wrapper around byte data that is intended to contain JSON text.
§CBOR Serialization
JSON implements the CBORTaggedCodable trait, which means it can be
serialized to and deserialized from CBOR with tag 262 (TAG_JSON).
§Examples
Creating JSON from a string:
use bc_components::JSON;
let json = JSON::from_string(r#"{"key": "value"}"#);
assert_eq!(json.as_str(), r#"{"key": "value"}"#);Creating JSON from bytes:
use bc_components::JSON;
let json = JSON::from_data(b"[1, 2, 3]");
assert_eq!(json.len(), 9);Implementations§
Trait Implementations§
Source§impl AsRef<JSON> for JSON
Provides a self-reference, enabling API consistency with other types.
impl AsRef<JSON> for JSON
Provides a self-reference, enabling API consistency with other types.
Source§impl CBORTagged for JSON
Identifies the CBOR tags used for JSON serialization.
impl CBORTagged for JSON
Identifies the CBOR tags used for JSON serialization.
Source§impl CBORTaggedDecodable for JSON
Defines how JSON is decoded from CBOR.
impl CBORTaggedDecodable for JSON
Defines how JSON is decoded from CBOR.
Source§fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
Source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
Source§impl CBORTaggedEncodable for JSON
Defines how JSON is encoded as CBOR (as a byte string).
impl CBORTaggedEncodable for JSON
Defines how JSON is encoded as CBOR (as a byte string).
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl<'a> From<&'a JSON> for &'a [u8]
Allows accessing the underlying data as a byte slice reference.
impl<'a> From<&'a JSON> for &'a [u8]
Allows accessing the underlying data as a byte slice reference.
Source§impl From<&JSON> for Vec<u8>
Converts a JSON reference into a Vec<u8> containing the JSON bytes.
impl From<&JSON> for Vec<u8>
Converts a JSON reference into a Vec<u8> containing the JSON bytes.
impl Eq for JSON
impl StructuralPartialEq for JSON
Auto Trait Implementations§
impl Freeze for JSON
impl RefUnwindSafe for JSON
impl Send for JSON
impl Sync for JSON
impl Unpin for JSON
impl UnwindSafe for JSON
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> CBORDecodable for T
impl<T> CBORDecodable for T
Source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)