Unsafe operations
c_str_to_static_slice
- Form a slice from a C stringfrom_buf_len
- Create a Rust string from a *u8 buffer of the given lengthfrom_byte
- Converts a byte to a string.from_c_str
- Create a Rust string from a null-terminated C stringfrom_utf8
- Converts a vector of bytes to a new owned string.from_utf8_owned
- Converts an owned vector of bytes to a new owned stringpop_byte
- Removes the last byte from a string and returns itpush_byte
- Appends a byte to a stringset_len
- Sets the length of a stringshift_byte
- Removes the first byte from a string and returns itslice_bytes
- Takes a bytewise (not UTF-8) slice from a string.slice_unchecked
- Takes a bytewise (not UTF-8) slice from a string.strdup_uniq
c_str_to_static_slice
unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str
Form a slice from a C string. Unsafe because the caller must ensure the C string has the static lifetime, or else the return value may be invalidated later.
from_buf_len
unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str
Create a Rust string from a *u8 buffer of the given length
from_byte
unsafe fn from_byte(u: u8) -> ~str
Converts a byte to a string.
from_c_str
unsafe fn from_c_str(buf: *libc::c_char) -> ~str
Create a Rust string from a null-terminated C string
from_utf8
unsafe fn from_utf8(v: &[u8]) -> ~str
Converts a vector of bytes to a new owned string.
from_utf8_owned
unsafe fn from_utf8_owned(v: ~[u8]) -> ~str
Converts an owned vector of bytes to a new owned string. This assumes that the utf-8-ness of the vector has already been validated
pop_byte
unsafe fn pop_byte(s: &mut ~str) -> u8
Removes the last byte from a string and returns it. (Not UTF-8 safe).
push_byte
unsafe fn push_byte(s: &mut ~str, b: u8)
Appends a byte to a string. (Not UTF-8 safe).
set_len
unsafe fn set_len(s: &mut ~str, new_len: uint)
Sets the length of a string
This will explicitly set the size of the string, without actually modifying its buffers, so it is up to the caller to ensure that the string is actually the specified size.
shift_byte
unsafe fn shift_byte(s: &mut ~str) -> u8
Removes the first byte from a string and returns it. (Not UTF-8 safe).
slice_bytes
unsafe fn slice_bytes<'a>(s: &'a str, begin: uint, end: uint) -> &'a str
Takes a bytewise (not UTF-8) slice from a string.
Returns the substring from [begin
..end
).
If begin is greater than end. If end is greater than the length of the string.
slice_unchecked
unsafe fn slice_unchecked<'a>(s: &'a str, begin: uint, end: uint) -> &'a str
Takes a bytewise (not UTF-8) slice from a string.
Returns the substring from [begin
..end
).
Caller must check slice boundaries!
strdup_uniq
unsafe fn strdup_uniq(ptr: *u8, len: uint) -> ~str