We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0bdc99d commit 2a9e763Copy full SHA for 2a9e763
src/libstd/c_str.rs
@@ -152,8 +152,7 @@ impl CString {
152
pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
153
if self.buf.is_null() { fail!("CString is null!"); }
154
unsafe {
155
- let len = ptr::position(self.buf, |c| *c == 0);
156
- cast::transmute((self.buf, len + 1))
+ cast::transmute((self.buf, self.len() + 1))
157
}
158
159
@@ -187,6 +186,15 @@ impl Drop for CString {
187
186
188
189
+impl Container for CString {
190
+ #[inline]
191
+ fn len(&self) -> uint {
192
+ unsafe {
193
+ ptr::position(self.buf, |c| *c == 0)
194
+ }
195
196
+}
197
+
198
/// A generic trait for converting a value to a CString.
199
pub trait ToCStr {
200
/// Copy the receiver into a CString.
0 commit comments