Skip to content

Commit 0559bed

Browse files
committed
Rename copy_from_slice to just from_slice
1 parent 4e0632b commit 0559bed

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn encode(hash: Hash, input: &[u8]) -> Result<Multihash, EncodeError> {
116116
output.extend_from_slice(size);
117117
output.extend_from_slice(input);
118118
Ok(Multihash {
119-
storage: Storage::copy_from_slice(&output),
119+
storage: Storage::from_slice(&output),
120120
})
121121
} else {
122122
let (offset, mut output) = encode_hash(hash);
@@ -139,7 +139,7 @@ pub fn encode(hash: Hash, input: &[u8]) -> Result<Multihash, EncodeError> {
139139
});
140140

141141
Ok(Multihash {
142-
storage: Storage::copy_from_slice(&output),
142+
storage: Storage::from_slice(&output),
143143
})
144144
}
145145
}
@@ -196,7 +196,7 @@ impl Multihash {
196196
});
197197
}
198198
Ok(Multihash {
199-
storage: Storage::copy_from_slice(&bytes),
199+
storage: Storage::from_slice(&bytes),
200200
})
201201
}
202202

@@ -342,7 +342,7 @@ impl<'a> MultihashRef<'a> {
342342
/// This operation allocates.
343343
pub fn to_owned(&self) -> Multihash {
344344
Multihash {
345-
storage: Storage::copy_from_slice(self.bytes),
345+
storage: Storage::from_slice(self.bytes),
346346
}
347347
}
348348

src/storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Storage {
2121
}
2222

2323
/// creates storage from a vec. Note that this will not preserve the size.
24-
pub fn copy_from_slice(slice: &[u8]) -> Self {
24+
pub fn from_slice(slice: &[u8]) -> Self {
2525
if slice.len() <= MAX_INLINE {
2626
let mut data: [u8; MAX_INLINE] = [0; MAX_INLINE];
2727
data[..slice.len()].copy_from_slice(slice);

tests/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,8 @@ fn multihash_ref_errors() {
276276
"Should error on wrong hash length"
277277
);
278278
}
279+
280+
#[test]
281+
fn multihash_size() {
282+
assert_eq!(std::mem::size_of::<Multihash>(), 40);
283+
}

0 commit comments

Comments
 (0)