pub struct RawJsonMember<'text, 'raw, 'a> { /* private fields */ }Expand description
Represents a member access result for a JSON object.
This struct is returned by RawJsonValue::to_member() and allows you to handle
both present and missing object members. It wraps an optional value that is
Some if the member exists and None if it doesn’t.
§Examples
let json = RawJson::parse(r#"{"name": "Alice", "age": 30}"#)?;
let obj = json.value();
// Access an existing member
let name_member = obj.to_member("name")?;
let name: String = name_member.required()?.try_into()?;
assert_eq!(name, "Alice");
// Access a missing member
let city_member = obj.to_member("city")?;
let city: Option<String> = city_member.try_into()?;
assert_eq!(city, None);Implementations§
Source§impl<'text, 'raw, 'a> RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> RawJsonMember<'text, 'raw, 'a>
Sourcepub fn required(self) -> Result<RawJsonValue<'text, 'raw>, JsonParseError>
pub fn required(self) -> Result<RawJsonValue<'text, 'raw>, JsonParseError>
Returns the member value if it exists, or an error if it’s missing.
This method is useful when you need to ensure that a required member is present in the JSON object.
§Examples
let json = RawJson::parse(r#"{"name": "Alice"}"#)?;
let obj = json.value();
// Required member exists
let name = obj.to_member("name")?.required()?;
assert_eq!(name.to_unquoted_string_str()?, "Alice");
// Required member missing - returns error
let age_result = obj.to_member("age")?.required();
assert!(age_result.is_err());Trait Implementations§
Source§impl<'text, 'raw, 'a> Clone for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> Clone for RawJsonMember<'text, 'raw, 'a>
Source§fn clone(&self) -> RawJsonMember<'text, 'raw, 'a>
fn clone(&self) -> RawJsonMember<'text, 'raw, 'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'text, 'raw, 'a> Debug for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> Debug for RawJsonMember<'text, 'raw, 'a>
Source§impl<'text, 'raw, 'a> Hash for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> Hash for RawJsonMember<'text, 'raw, 'a>
Source§impl<'text, 'raw, 'a> Ord for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> Ord for RawJsonMember<'text, 'raw, 'a>
Source§fn cmp(&self, other: &RawJsonMember<'text, 'raw, 'a>) -> Ordering
fn cmp(&self, other: &RawJsonMember<'text, 'raw, 'a>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<'text, 'raw, 'a> PartialEq for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> PartialEq for RawJsonMember<'text, 'raw, 'a>
Source§fn eq(&self, other: &RawJsonMember<'text, 'raw, 'a>) -> bool
fn eq(&self, other: &RawJsonMember<'text, 'raw, 'a>) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl<'text, 'raw, 'a> PartialOrd for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> PartialOrd for RawJsonMember<'text, 'raw, 'a>
Source§impl<'text, 'raw, 'a, T> TryFrom<RawJsonMember<'text, 'raw, 'a>> for Option<T>
impl<'text, 'raw, 'a, T> TryFrom<RawJsonMember<'text, 'raw, 'a>> for Option<T>
Source§type Error = JsonParseError
type Error = JsonParseError
The type returned in the event of a conversion error.
impl<'text, 'raw, 'a> Copy for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> Eq for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> StructuralPartialEq for RawJsonMember<'text, 'raw, 'a>
Auto Trait Implementations§
impl<'text, 'raw, 'a> Freeze for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> RefUnwindSafe for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> Send for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> Sync for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> Unpin for RawJsonMember<'text, 'raw, 'a>
impl<'text, 'raw, 'a> UnwindSafe for RawJsonMember<'text, 'raw, 'a>
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