pub struct Json { /* private fields */ }
Implementations§
Source§impl Json
impl Json
Sourcepub fn to_object<T: DeserializeOwned>(&self) -> Result<T, Error>
pub fn to_object<T: DeserializeOwned>(&self) -> Result<T, Error>
Deserializes the JSON data into a custom type.
This method attempts to deserialize the stored JSON value into any type
that implements DeserializeOwned
. This is useful for converting the
raw JSON configuration into strongly-typed structs.
§Type Parameters
T
- The target type to deserialize into. Must implementDeserializeOwned
.
§Returns
An instance of type T
containing the deserialized data.
§Panics
This method currently panics (via todo!()
) as the implementation is not
yet complete. In the future, it will return a Result
type to handle
deserialization errors gracefully.
§Examples
ⓘ
use serde::{Deserialize, Serialize};
use serde_json::json;
use apollo_client::namespace::json::Json;
#[derive(Deserialize, Serialize)]
struct DatabaseConfig {
host: String,
port: u16,
}
let json_data = json!({
"host": "localhost",
"port": 5432
});
let json_namespace = Json::from(json_data);
// let config: DatabaseConfig = json_namespace.to_object(); // Will work when implemented
Trait Implementations§
Source§impl TryFrom<Value> for Json
Converts a serde_json::Value
into a Json
instance.
impl TryFrom<Value> for Json
Converts a serde_json::Value
into a Json
instance.
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
Mutably borrows from an owned value. Read more