blob: 8dadde35cfa6e0d35e5029952ad5c93c5da39d9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
pub trait Writeable {
fn to_byte_buf(&self) -> Box<[u8]>;
}
impl Writeable for &str {
fn to_byte_buf(&self) -> Box<[u8]> {
return Box::from(self.as_bytes());
}
}
impl Writeable for char {
fn to_byte_buf(&self) -> Box<[u8]> {
let mut buf = [0; 4];
return self
.encode_utf8(&mut buf)
.to_owned()
.into_boxed_str()
.into_boxed_bytes();
}
}
|