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
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 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 implementDeserializeOwned
.
§Returns
Ok(T)
- The deserialized configuration objectErr(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 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.
§Arguments
json_value
- The raw JSON value containing YAML configuration data
§Returns
Ok(Yaml)
- A new Yaml instance containing the parsed configurationErr(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();