Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit 740f705

Browse files
authored
Merge pull request #164 from idan-weizman/master
implementations with ?Sized for Hex and Base64 traits
2 parents 6488e2b + aeba6d6 commit 740f705

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/base64.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ impl ToBase64 for [u8] {
191191
}
192192
}
193193

194+
impl<'a, T: ?Sized + ToBase64> ToBase64 for &'a T {
195+
fn to_base64(&self, config: Config) -> String {
196+
(**self).to_base64(config)
197+
}
198+
}
199+
194200
/// A trait for converting from base64 encoded values.
195201
pub trait FromBase64 {
196202
/// Converts the value of `self`, interpreted as base64 encoded data, into
@@ -317,6 +323,12 @@ impl FromBase64 for [u8] {
317323
}
318324
}
319325

326+
impl<'a, T: ?Sized + FromBase64> FromBase64 for &'a T {
327+
fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error> {
328+
(**self).from_base64()
329+
}
330+
}
331+
320332
/// Base64 decoding lookup table, generated using:
321333
/// ```rust
322334
/// let mut ch = 0u8;

src/hex.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ impl ToHex for [u8] {
5353
}
5454
}
5555

56+
impl<'a, T: ?Sized + ToHex> ToHex for &'a T {
57+
fn to_hex(&self) -> String {
58+
(**self).to_hex()
59+
}
60+
}
61+
5662
/// A trait for converting hexadecimal encoded values
5763
pub trait FromHex {
5864
/// Converts the value of `self`, interpreted as hexadecimal encoded data,
@@ -155,6 +161,12 @@ impl FromHex for str {
155161
}
156162
}
157163

164+
impl<'a, T: ?Sized + FromHex> FromHex for &'a T {
165+
fn from_hex(&self) -> Result<Vec<u8>, FromHexError> {
166+
(**self).from_hex()
167+
}
168+
}
169+
158170
#[cfg(test)]
159171
mod tests {
160172
use hex::{FromHex, ToHex};

0 commit comments

Comments
 (0)