Finish challenge 14.
This commit is contained in:
@@ -6,6 +6,10 @@ use std::fmt::Write; // need to import this trait
|
||||
pub struct Bytes(pub Vec<u8>);
|
||||
|
||||
impl Bytes {
|
||||
pub fn empty() -> Bytes {
|
||||
Bytes(vec![])
|
||||
}
|
||||
|
||||
pub fn from_utf8(s: &str) -> Bytes {
|
||||
Bytes(s.as_bytes().iter().map(|c| c.clone()).collect())
|
||||
}
|
||||
@@ -16,6 +20,10 @@ impl Bytes {
|
||||
String::from(std::str::from_utf8(&v).unwrap())
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
pub fn get_block(&self, block_index: usize, block_size: usize) -> Bytes {
|
||||
Bytes(self.0[(block_index * block_size)..(block_index + 1) * block_size].to_vec())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user