pub struct YsonValue {
pub attributes: Option<BTreeMap<Vec<u8>, YsonValue>>,
pub node: YsonNode,
}Expand description
Represents a complete YSON value, including its optional attributes and data node.
Fields§
§attributes: Option<BTreeMap<Vec<u8>, YsonValue>>Optional attributes associated with this value. In YSON, attributes are stored as a map of byte strings to other YSON values.
node: YsonNodeThe data content of this YSON node.
Implementations§
Source§impl YsonValue
impl YsonValue
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Attempts to interpret the node as a UTF-8 string.
Returns None if the node is not a string or if the bytes are not valid UTF-8.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for YsonValue
impl<'de> Deserialize<'de> for YsonValue
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'a> Index<&'a str> for YsonValue
impl<'a> Index<&'a str> for YsonValue
Source§fn index(&self, key: &'a str) -> &Self::Output
fn index(&self, key: &'a str) -> &Self::Output
Provides convenient access to map elements or attributes using index notation.
§Panics
Panics if the key is not found or if the value is not a map.
§Examples
use ytsaurus_yson::{YsonValue, from_slice, YsonFormat};
let input = b"<status=\"ok\">{id=1u}";
let value: YsonValue = from_slice(input, YsonFormat::Text).unwrap();
// Access an attribute with '@' prefix
assert_eq!(value["@status"].as_str(), Some("ok"));
// Access a map field directly
// Note: value["id"] would work if it were a mapSource§impl Serialize for YsonValue
impl Serialize for YsonValue
Source§fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
Round-trips through crate::to_vec/crate::from_slice.
Note that maps are stored in a BTreeMap, so keys come back out in
sorted order rather than in the order they appeared in the input. The
round-trip therefore preserves the value, not the exact byte layout.