summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2012-07-03 21:30:09 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2012-07-03 21:30:09 -0700
commit2f9c0114fa0b0d3b018b37dcfd0eafaf01d6c48a (patch)
tree9de67e53b1647ab1d66fd37f53f0651d245a2120 /src/libcore
parentabee1589451c513bb0b77bb7001a0ea592dc67c3 (diff)
downloadrust-2f9c0114fa0b0d3b018b37dcfd0eafaf01d6c48a.tar.gz
rust-2f9c0114fa0b0d3b018b37dcfd0eafaf01d6c48a.zip
Add a to_bytes iface and a handful of impls
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/to_bytes.rs19
1 files changed, 19 insertions, 0 deletions
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) }
+}