Skip to content

Commit

Permalink
#74 more examples in doc
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 11, 2023
1 parent 75b03fc commit 6f5bfcd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl From<bool> for Hex {
impl FromStr for Hex {
type Err = anyhow::Error;

/// Creeate a `Hex` from a `&str` containing a hexadecimal representation of some data,
/// Create a `Hex` from a `&str` containing a hexadecimal representation of some data,
/// for example, `DE-AD-BE-EF-20-22`.
///
/// ```
Expand All @@ -385,6 +385,18 @@ impl FromStr for Hex {
/// assert_eq!("DE-AD-BE-EF-20-22", d.print());
/// assert_eq!("DE-AD-BE-EF-20-22", d2.print());
/// ```
///
/// An empty `Hex` may be created either from an empty string
/// or `"--"`:
///
/// ```
/// use sodg::Hex;
/// use std::str::FromStr;
/// let d1: Hex = Hex::from_str("--").unwrap();
/// let d2: Hex = Hex::from_str("").unwrap();
/// assert_eq!(Hex::empty(), d1);
/// assert_eq!(Hex::empty(), d2);
/// ```
fn from_str(hex: &str) -> std::result::Result<Self, Self::Err> {
let s = hex.replace('-', "");
Ok(Self::from_vec(hex::decode(s)?))
Expand Down

0 comments on commit 6f5bfcd

Please sign in to comment.