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 serde_yaml::Value
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
impl Yaml
Sourcepub fn to_object<T: DeserializeOwned>(&self) -> Result<T, Error>
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 value 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 implementDeserializeOwned
.
§Returns
An instance of type T
containing the deserialized data.
§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().unwrap();
Trait Implementations§
Source§impl TryFrom<Value> for Yaml
Converts a serde_json::Value
into a Yaml
instance.
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.
§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();