From 158117e4096f5af571e79e1a33d91f09e7b2cc5d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 5 Apr 2020 11:39:58 +0100 Subject: Rename Options to Deserializer --- serde_dhall/src/options.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'serde_dhall/src') diff --git a/serde_dhall/src/options.rs b/serde_dhall/src/options.rs index f260572..237647f 100644 --- a/serde_dhall/src/options.rs +++ b/serde_dhall/src/options.rs @@ -12,13 +12,13 @@ enum Source<'a> { // Url(&'a str), } -/// Options and flags which can be used to configure how a dhall value is read. +/// Controls how a dhall value is read. /// /// This builder exposes the ability to configure how a value is deserialized and what operations /// are permitted during evaluation. The functions in the crate root are aliases for /// commonly used options using this builder. /// -/// Generally speaking, when using `Options`, you'll create it with `from_str` or `from_file`, then +/// Generally speaking, when using `Deserializer`, you'll create it with `from_str` or `from_file`, then /// chain calls to methods to set each option, then call `parse`. This will give you a /// `serde_dhall::Result` where `T` a deserializable type of your choice. /// @@ -48,9 +48,9 @@ enum Source<'a> { /// # Ok(()) /// # } /// ``` -/// /// TODO +/// TODO #[derive(Debug, Clone)] -pub struct Options<'a, T> { +pub struct Deserializer<'a, T> { source: Source<'a>, annot: Option, allow_imports: bool, @@ -59,9 +59,9 @@ pub struct Options<'a, T> { target_type: std::marker::PhantomData, } -impl<'a, T> Options<'a, T> { +impl<'a, T> Deserializer<'a, T> { fn default_with_source(source: Source<'a>) -> Self { - Options { + Deserializer { source, annot: None, allow_imports: true, @@ -135,14 +135,22 @@ impl<'a, T> Options<'a, T> { } } -/// TODO -pub fn from_str<'a, T>(s: &'a str) -> Options<'a, T> { - Options::from_str(s) +/// Deserialize an instance of type `T` from a string of Dhall text. +/// +/// This returns a [`Deserializer`] object. Call the [`parse`] method to get the deserialized value, or +/// use other [`Deserializer`] methods to add type annotations or control import behavior beforehand. +/// +/// [`Deserializer`]: struct.Deserializer.html +/// [`parse`]: struct.Deserializer.html#method.parse +pub fn from_str<'a, T>(s: &'a str) -> Deserializer<'a, T> { + Deserializer::from_str(s) } + /// TODO -pub fn from_file<'a, T, P: AsRef>(path: P) -> Options<'a, T> { - Options::from_file(path) +pub fn from_file<'a, T, P: AsRef>(path: P) -> Deserializer<'a, T> { + Deserializer::from_file(path) } -// pub fn from_url<'a, T>(url: &'a str) -> Options<'a, T> { -// Options::from_url(url) + +// pub fn from_url<'a, T>(url: &'a str) -> Deserializer<'a, T> { +// Deserializer::from_url(url) // } -- cgit v1.2.3