summaryrefslogtreecommitdiffstats
path: root/src/writeable.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/writeable.rs')
-rw-r--r--src/writeable.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/writeable.rs b/src/writeable.rs
new file mode 100644
index 0000000..8dadde3
--- /dev/null
+++ b/src/writeable.rs
@@ -0,0 +1,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();
+ }
+}