openapi_types/yaml/
loader.rs1use crate::yaml::YamlLoaderError::Conversion;
2use crate::{Error, Result};
3use YamlLoaderError::CannotScanYaml;
4use gesha_collections::yaml::{YamlError, YamlValue};
5use std::fmt::Debug;
6use yaml_rust::YamlLoader;
7
8pub fn load_from_str<A>(contents: &str) -> Result<A>
9where
10 A: TryFrom<YamlValue, Error = YamlError>,
11{
12 let mut yamls = YamlLoader::load_from_str(contents).map_err(|e| CannotScanYaml {
13 detail: Box::new(e),
14 })?;
15 let underlying = yamls.swap_remove(0);
16 let value = YamlValue::try_from(underlying).map_err(Conversion)?;
17 let a = A::try_from(value).map_err(Conversion)?;
18 Ok(a)
19}
20
21#[derive(Debug)]
22pub enum YamlLoaderError {
23 CannotScanYaml { detail: Box<dyn Debug + Send> },
24 Conversion(YamlError),
25}
26
27impl From<YamlLoaderError> for Error {
28 fn from(this: YamlLoaderError) -> Self {
29 Self::YamlLoader(this)
30 }
31}