Json

Struct Json 

Source
pub struct Json { /* private fields */ }

Implementations§

Source§

impl Json

Source

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 implement DeserializeOwned.
§Returns
  • Ok(T) - The deserialized configuration object
  • Err(serde_json::Error) - If deserialization fails due to format mismatches, missing fields, or type conversion failures
§Errors

This method will return an error if:

  • The JSON structure doesn’t match the expected type
  • Required fields are missing from the JSON
  • Type conversion fails (e.g., string to number)
  • The JSON is malformed or invalid
§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()?;

Trait Implementations§

Source§

impl Clone for Json

Source§

fn clone(&self) -> Json

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Json

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Json> for JsValue

Source§

fn from(val: Json) -> Self

Converts to this type from the input type.
Source§

impl Serialize for Json

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<Value> for Json

Converts a serde_json::Value into a Json instance.

This implementation allows for easy creation of Json instances from raw JSON data, typically used by the namespace detection system.

§Arguments

  • json_value - The raw JSON value containing configuration data

§Returns

  • Ok(Json) - A new Json instance containing the parsed configuration
  • Err(Error::ContentNotFound) - If the JSON value doesn’t contain a “content” field
  • Err(Error::DeserializeError) - If the content field cannot be parsed as valid JSON

§Errors

This function will return an error if:

  • The JSON value doesn’t contain a “content” field
  • The “content” field is not a string
  • The content string cannot be parsed as valid JSON

§Examples

use serde_json::json;
use apollo_client::namespace::json::Json;

let json_data = json!({"content": "{\"key\": \"value\"}"});
let json_namespace = Json::try_from(json_data)?;
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(json_value: Value) -> Result<Self, Self::Error>

Performs the conversion.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,