Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions mcf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ impl<'a> McfHashRef<'a> {
}
}

impl<'a> From<McfHashRef<'a>> for &'a str {
fn from(hash: McfHashRef<'a>) -> &'a str {
hash.0
}
}

#[cfg(feature = "alloc")]
impl From<McfHashRef<'_>> for alloc::string::String {
fn from(hash: McfHashRef<'_>) -> Self {
hash.0.into()
}
}

impl<'a> TryFrom<&'a str> for McfHashRef<'a> {
type Error = Error;

fn try_from(s: &'a str) -> Result<Self> {
Self::new(s)
}
}

#[cfg(feature = "alloc")]
mod allocating {
use crate::{Base64, Error, Field, Fields, McfHashRef, Result, fields, validate, validate_id};
Expand Down Expand Up @@ -177,6 +198,14 @@ mod allocating {
}
}

impl TryFrom<&str> for McfHash {
type Error = Error;

fn try_from(s: &str) -> Result<Self> {
Self::new(s)
}
}

impl fmt::Display for McfHash {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
Expand Down