Skip to content

Commit da76819

Browse files
committed
Organize From implementations
1 parent 4525f29 commit da76819

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

packages/std/src/binary.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ impl fmt::Debug for Binary {
8383
}
8484
}
8585

86-
impl From<&[u8]> for Binary {
87-
fn from(binary: &[u8]) -> Self {
88-
Self(binary.to_vec())
89-
}
90-
}
91-
9286
/// Just like Vec<u8>, Binary is a smart pointer to [u8].
9387
/// This implements `*binary` for us and allows us to
9488
/// do `&*binary`, returning a `&[u8]` from a `&Binary`.
@@ -102,14 +96,21 @@ impl Deref for Binary {
10296
}
10397
}
10498

105-
// Reference
99+
// Slice
100+
impl From<&[u8]> for Binary {
101+
fn from(binary: &[u8]) -> Self {
102+
Self(binary.to_vec())
103+
}
104+
}
105+
106+
// Array reference
106107
impl<const LENGTH: usize> From<&[u8; LENGTH]> for Binary {
107108
fn from(source: &[u8; LENGTH]) -> Self {
108109
Self(source.to_vec())
109110
}
110111
}
111112

112-
// Owned
113+
// Owned array
113114
impl<const LENGTH: usize> From<[u8; LENGTH]> for Binary {
114115
fn from(source: [u8; LENGTH]) -> Self {
115116
Self(source.into())

packages/std/src/hex_binary.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ impl fmt::Debug for HexBinary {
7979
}
8080
}
8181

82-
impl From<&[u8]> for HexBinary {
83-
fn from(binary: &[u8]) -> Self {
84-
Self(binary.to_vec())
85-
}
86-
}
87-
8882
/// Just like Vec<u8>, HexBinary is a smart pointer to [u8].
8983
/// This implements `*data` for us and allows us to
9084
/// do `&*data`, returning a `&[u8]` from a `&HexBinary`.
@@ -98,14 +92,21 @@ impl Deref for HexBinary {
9892
}
9993
}
10094

101-
// Reference
95+
// Slice
96+
impl From<&[u8]> for HexBinary {
97+
fn from(binary: &[u8]) -> Self {
98+
Self(binary.to_vec())
99+
}
100+
}
101+
102+
// Array reference
102103
impl<const LENGTH: usize> From<&[u8; LENGTH]> for HexBinary {
103104
fn from(source: &[u8; LENGTH]) -> Self {
104105
Self(source.to_vec())
105106
}
106107
}
107108

108-
// Owned
109+
// Owned array
109110
impl<const LENGTH: usize> From<[u8; LENGTH]> for HexBinary {
110111
fn from(source: [u8; LENGTH]) -> Self {
111112
Self(source.into())

0 commit comments

Comments
 (0)