Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ impl ToBase64 for [u8] {
}
}

impl<'a, T: ?Sized + ToBase64> ToBase64 for &'a T {
fn to_base64(&self, config: Config) -> String {
(**self).to_base64(config)
}
}

/// A trait for converting from base64 encoded values.
pub trait FromBase64 {
/// Converts the value of `self`, interpreted as base64 encoded data, into
Expand Down Expand Up @@ -317,6 +323,12 @@ impl FromBase64 for [u8] {
}
}

impl<'a, T: ?Sized + FromBase64> FromBase64 for &'a T {
fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error> {
(**self).from_base64()
}
}

/// Base64 decoding lookup table, generated using:
/// ```rust
/// let mut ch = 0u8;
Expand Down
12 changes: 12 additions & 0 deletions src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ impl ToHex for [u8] {
}
}

impl<'a, T: ?Sized + ToHex> ToHex for &'a T {
fn to_hex(&self) -> String {
(**self).to_hex()
}
}

/// A trait for converting hexadecimal encoded values
pub trait FromHex {
/// Converts the value of `self`, interpreted as hexadecimal encoded data,
Expand Down Expand Up @@ -155,6 +161,12 @@ impl FromHex for str {
}
}

impl<'a, T: ?Sized + FromHex> FromHex for &'a T {
fn from_hex(&self) -> Result<Vec<u8>, FromHexError> {
(**self).from_hex()
}
}

#[cfg(test)]
mod tests {
use hex::{FromHex, ToHex};
Expand Down