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 2b2347e commit 556ee27
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl Hex {
Ok(f64::from_be_bytes(*a))
}

/// Turn it into `string`.
/// Turn it into `String` in UTF-8 encoding.
///
/// ```
/// use sodg::Hex;
Expand All @@ -241,6 +241,22 @@ impl Hex {
/// let d = Hex::from_vec([0xCA, 0xFE].to_vec());
/// assert_eq!("CA-FE", d.print());
/// ```
///
/// A string of one letter will be printed as `xx`, without the trailing dash:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_vec([0xCA].to_vec());
/// assert_eq!("CA", d.print());
/// ```
///
/// An empty string will be printed as `--`:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::empty();
/// assert_eq!("--", d.print());
/// ```
pub fn print(&self) -> String {
if self.bytes().is_empty() {
"--".to_string()
Expand Down

0 comments on commit 556ee27

Please sign in to comment.