Skip to content

Commit

Permalink
feat: Remove debug prints, provide yaml::from_str/owned
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Oct 5, 2024
1 parent 02b1d47 commit 65c5c75
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 0 additions & 1 deletion merde_json/src/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ mod tests {
}

let ev = self.inner.next()?;
eprintln!("> {:?}", ev);
Ok(ev)
}

Expand Down
22 changes: 20 additions & 2 deletions merde_yaml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::str::Chars;

use merde_core::{ArrayStart, Deserializer, Event};
use merde_core::{ArrayStart, Deserialize, DeserializeOwned, Deserializer, Event};
use yaml_rust2::{parser::Parser, scanner::TScalarStyle, ScanError};

/// A YAML deserializer, that implements [`merde_core::Deserializer`].
Expand Down Expand Up @@ -79,7 +79,6 @@ impl<'s> Deserializer<'s> for YamlDeserializer<'s> {
return Err(e.into());
}
};
println!("ev = {ev:?}");

use yaml_rust2::Event as YEvent;

Expand Down Expand Up @@ -176,3 +175,22 @@ impl<'s> Deserializer<'s> for YamlDeserializer<'s> {
T::deserialize(self).await
}
}

/// Deserialize an instance of type `T` from a string of YAML text.
pub fn from_str<'s, T>(s: &'s str) -> Result<T, MerdeYamlError<'s>>
where
T: Deserialize<'s>,
{
let mut deser = YamlDeserializer::new(s);
deser.deserialize::<T>()
}

/// Deserialize an instance of type `T` from a string of YAML text,
/// and return its static variant e.g. (CowStr<'static>, etc.)
pub fn from_str_owned<T>(s: &str) -> Result<T, MerdeYamlError<'_>>
where
T: DeserializeOwned,
{
let mut deser = YamlDeserializer::new(s);
T::deserialize_owned(&mut deser)
}

0 comments on commit 65c5c75

Please sign in to comment.