about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/c_str.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs
index 823cc0db4b9..82726627bc8 100644
--- a/src/libstd/c_str.rs
+++ b/src/libstd/c_str.rs
@@ -152,8 +152,7 @@ impl CString {
     pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
         if self.buf.is_null() { fail!("CString is null!"); }
         unsafe {
-            let len = ptr::position(self.buf, |c| *c == 0);
-            cast::transmute((self.buf, len + 1))
+            cast::transmute((self.buf, self.len() + 1))
         }
     }
 
@@ -187,6 +186,15 @@ impl Drop for CString {
     }
 }
 
+impl Container for CString {
+    #[inline]
+    fn len(&self) -> uint {
+        unsafe {
+            ptr::position(self.buf, |c| *c == 0)
+        }
+    }
+}
+
 /// A generic trait for converting a value to a CString.
 pub trait ToCStr {
     /// Copy the receiver into a CString.