From 2f9c0114fa0b0d3b018b37dcfd0eafaf01d6c48a Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 3 Jul 2012 21:30:09 -0700 Subject: [PATCH] Add a to_bytes iface and a handful of impls --- src/libcore/to_bytes.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/libcore/to_bytes.rs diff --git a/src/libcore/to_bytes.rs b/src/libcore/to_bytes.rs new file mode 100644 index 00000000000..4bfd16344cb --- /dev/null +++ b/src/libcore/to_bytes.rs @@ -0,0 +1,19 @@ +iface to_bytes { + fn to_bytes() -> ~[u8]; +} + +impl of to_bytes for ~[u8] { + fn to_bytes() -> ~[u8] { copy self } +} + +impl of to_bytes for @~[u8] { + fn to_bytes() -> ~[u8] { copy *self } +} + +impl of to_bytes for str { + fn to_bytes() -> ~[u8] { str::bytes(self) } +} + +impl of to_bytes for @str { + fn to_bytes() -> ~[u8] { str::bytes(*self) } +}