pub enum JsonData {
Null,
Bool(bool),
Integer(i64),
Float(f64),
String(String),
Array(Vec<JsonData>),
Object(HashMap<String, JsonData>),
}Expand description
Domain-specific representation of JSON-like data This replaces serde_json::Value to maintain Clean Architecture principles
Variants§
Null
Null value
Bool(bool)
Boolean value
Integer(i64)
Integer value
Float(f64)
Float value (stored as f64 for simplicity)
String(String)
String value
Array(Vec<JsonData>)
Array of JsonData values
Object(HashMap<String, JsonData>)
Object with string keys and JsonData values
Implementations§
Source§impl JsonData
impl JsonData
Sourcepub fn float(value: f64) -> Result<JsonData, DomainError>
pub fn float(value: f64) -> Result<JsonData, DomainError>
Create a new float value.
Returns Err when value is NaN or infinite. JSON (RFC 8259 §6) does not
allow non-finite numbers, so a JsonData containing one could never be
serialized to valid JSON.
§Examples
use pjson_rs_domain::value_objects::JsonData;
assert!(JsonData::float(3.14).is_ok());
assert!(JsonData::float(f64::NAN).is_err());
assert!(JsonData::float(f64::INFINITY).is_err());Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Check if value is integer
Sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<JsonData>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<JsonData>>
Get mutable array value if this is an array
Sourcepub fn as_object(&self) -> Option<&HashMap<String, JsonData>>
pub fn as_object(&self) -> Option<&HashMap<String, JsonData>>
Get object value if this is an object
Sourcepub fn as_object_mut(&mut self) -> Option<&mut HashMap<String, JsonData>>
pub fn as_object_mut(&mut self) -> Option<&mut HashMap<String, JsonData>>
Get mutable object value if this is an object
Sourcepub fn get_path(&self, path: &str) -> Option<&JsonData>
pub fn get_path(&self, path: &str) -> Option<&JsonData>
Get nested value by path (dot notation)
Sourcepub fn set_path(&mut self, path: &str, value: JsonData) -> bool
pub fn set_path(&mut self, path: &str, value: JsonData) -> bool
Set nested value by path (dot notation)
Sourcepub fn memory_size(&self) -> usize
pub fn memory_size(&self) -> usize
Estimate memory size in bytes
Trait Implementations§
Source§impl<'de> Deserialize<'de> for JsonData
impl<'de> Deserialize<'de> for JsonData
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<JsonData, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<JsonData, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<&JsonDataDto> for JsonData
impl From<&JsonDataDto> for JsonData
Source§fn from(dto: &JsonDataDto) -> Self
fn from(dto: &JsonDataDto) -> Self
Source§impl From<JsonData> for JsonDataDto
impl From<JsonData> for JsonDataDto
Source§impl From<JsonDataDto> for JsonData
impl From<JsonDataDto> for JsonData
Source§fn from(dto: JsonDataDto) -> Self
fn from(dto: JsonDataDto) -> Self
Source§impl Serialize for JsonData
impl Serialize for JsonData
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for JsonData
impl StructuralPartialEq for JsonData
Auto Trait Implementations§
impl Freeze for JsonData
impl RefUnwindSafe for JsonData
impl Send for JsonData
impl Sync for JsonData
impl Unpin for JsonData
impl UnsafeUnpin for JsonData
impl UnwindSafe for JsonData
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§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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.