Yaml

Struct Yaml 

Source
pub struct Yaml { /* private fields */ }
Expand description

A wrapper around serde_yaml::Value for YAML-formatted configuration data.

This struct provides a type-safe interface for working with YAML configuration data retrieved from Apollo. It maintains the original YAML structure while providing convenient methods for deserialization into custom types.

§Thread Safety

This struct is Clone and Debug, making it easy to work with in concurrent environments. The underlying YAML string is also thread-safe.

§Examples

use serde_yaml;
use apollo_client::namespace::yaml::Yaml;

let yaml_data = serde_yaml::from_str("database:\n  host: localhost\n  port: 5432").unwrap();

let yaml_namespace = Yaml::from(yaml_data);

Implementations§

Source§

impl Yaml

Source

pub fn to_object<T: DeserializeOwned>(&self) -> Result<T, Error>

Deserializes the YAML data into a custom type.

This method attempts to deserialize the stored YAML string into any type that implements DeserializeOwned. This is useful for converting the raw YAML 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_yaml::Error) - If deserialization fails due to format mismatches, missing fields, or type conversion failures
§Errors

This method will return an error if:

  • The YAML structure doesn’t match the expected type
  • Required fields are missing from the YAML
  • Type conversion fails (e.g., string to number)
  • The YAML is malformed or invalid
§Examples
use serde::{Deserialize, Serialize};
use serde_yaml;
use apollo_client::namespace::yaml::Yaml;

#[derive(Deserialize, Serialize)]
struct DatabaseConfig {
    host: String,
    port: u16,
}

let yaml_data = serde_yaml::from_str("host: localhost\nport: 5432").unwrap();

let yaml_namespace = Yaml::from(yaml_data);
let config: DatabaseConfig = yaml_namespace.to_object()?;

Trait Implementations§

Source§

impl Clone for Yaml

Source§

fn clone(&self) -> Yaml

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 Yaml

Source§

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

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

impl From<Yaml> for JsValue

Source§

fn from(val: Yaml) -> Self

Converts to this type from the input type.
Source§

impl TryFrom<Value> for Yaml

Converts a serde_json::Value into a Yaml instance.

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

§Arguments

  • json_value - The raw JSON value containing YAML configuration data

§Returns

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

§Errors

This function will return an error if:

  • The JSON value doesn’t contain a “content” field
  • The “content” field is not a string

§Examples

use serde_json::json;
use apollo_client::namespace::yaml::Yaml;

let json_data = json!({"content": "name: MyApp\nversion: 1.0.0"});
let yaml_namespace = Yaml::try_from(json_data).unwrap();
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 Yaml

§

impl RefUnwindSafe for Yaml

§

impl Send for Yaml

§

impl Sync for Yaml

§

impl Unpin for Yaml

§

impl UnwindSafe for Yaml

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,