Unsafe operations
c_str_to_static_slice
- Form a slice from a C stringfrom_buf
- Create a Rust string from a null-terminated *u8 bufferfrom_buf_len
- Create a Rust string from a *u8 buffer of the given lengthfrom_byte
- Converts a byte to a string.from_bytes
- Converts a vector of bytes to a new owned string.from_bytes_owned
- Converts an owned vector of bytes to a new owned stringfrom_bytes_with_null
- Converts a vector of bytes to a stringfrom_c_str
- Create a Rust string from a null-terminated C stringfrom_c_str_len
- Create a Rust string from a *c_char
buffer of the given lengthpop_byte
- Removes the last byte from a string and returns itpush_byte
- Appends a byte to a stringset_len
- Sets the length of the string and adds the null terminatorshift_byte
- Removes the first byte from a string and returns itslice_bytes
- Takes a bytewise (not UTF-8) slice from a string.slice_bytes_owned
- Takes a bytewise (not UTF-8) slice from a string.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
unsafe fn from_buf(buf: *u8) -> ~str
Create a Rust string from a null-terminated *u8 buffer
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_bytes
unsafe fn from_bytes(v: &[u8]) -> ~str
Converts a vector of bytes to a new owned string.
from_bytes_owned
unsafe fn from_bytes_owned(mut 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
from_bytes_with_null
unsafe fn from_bytes_with_null<'a>(v: &'a [u8]) -> &'a str
Converts a vector of bytes to a string. The byte slice needs to contain valid utf8 and needs to be one byte longer than the string, if possible ending in a 0 byte.
from_c_str
unsafe fn from_c_str(c_str: *libc::c_char) -> ~str
Create a Rust string from a null-terminated C string
from_c_str_len
unsafe fn from_c_str_len(c_str: *libc::c_char, len: uint) -> ~str
Create a Rust string from a *c_char
buffer of the given length
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(v: &mut ~str, new_len: uint)
Sets the length of the string and adds the null terminator
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(s: &str, begin: uint, end: uint) -> &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_bytes_owned
unsafe fn slice_bytes_owned(s: &str, begin: uint, end: uint) -> ~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.