From dff33d2b46fb9d0179d0489490a4bec41700ae33 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Tue, 26 Jul 2022 18:31:16 +0300 Subject: [PATCH] chore: add more docs --- src/core.rs | 27 ++++++++++++++++++++++++--- src/error.rs | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/core.rs b/src/core.rs index ef570ab..ac75545 100644 --- a/src/core.rs +++ b/src/core.rs @@ -11,7 +11,7 @@ pub trait FormatFragment { /// Parse a value fragment from a ``EString``. /// -/// ``ParseFragment``’s `parse_frag` method is often used imlicitly, through ``EString``’s parse. +/// ``ParseFragment``’s `parse_frag` method is often used implicitly, through ``EString``’s parse. /// See [parse](EString::parse)’s documentation for examples. /// /// # Examples @@ -75,12 +75,33 @@ pub trait ParseFragment: Sized { pub struct EString(pub String); impl EString { - /// Parses inner string by type annotations and returns result. + /// Parses this inner string into another type. + /// + /// `parse` can parse into any type that implements the ``ParseFragment`` trait. /// /// # Errors /// - /// Will return `Err` if estring cannot parse inner fragment + /// Will return `Err` if estring cannot parse inner fragment into the desired type. /// + /// # Examples + /// + /// Basic usage + /// + /// ```rust + /// # use estring::{EString, ParseFragment}; + /// let fragment = EString::from("5"); + /// let res = i32::parse_frag(fragment); + /// assert_eq!(res, Ok(5)); + /// ``` + /// + /// Failing to parse: + /// + /// ```rust + /// # use estring::{EString, ParseFragment, Error, Reason}; + /// let fragment = EString::from("j"); + /// let res = i32::parse_frag(fragment.clone()); + /// assert_eq!(res, Err(Error(fragment, Reason::Parse))); + /// ``` #[inline] pub fn parse(self) -> crate::Result { T::parse_frag(self) diff --git a/src/error.rs b/src/error.rs index 3d99596..eebec96 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,7 @@ use crate::core::EString; /// The error type for operations interacting with ``EString``’s fragments. -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub struct Error(pub EString, pub Reason); /// The reason for the failure to parse.