Struct c_fixed_string::CFixedString
[−]
[src]
pub struct CFixedString { /* fields omitted */ }
This type owns a fixed length buffer containing a C-style string. The string is terminated by the first null byte in the buffer, or by the length of the buffer if no null byte is present.
The length of the buffer is known as the limit of the CFixedString.
The len()
method returns the length of the string within the buffer.
Any bytes after the first null byte are not considered part of the string and may contain garbage data. When comparing or hashing CFixedStrings, these bytes are not included.
Performance
Be aware that many of the methods on this type which would normally be expected to run in constant time may run in time linear in the length of the string. For this reason, it is recommended to use the type only for interop with C code, and to convert to a standard string or byte buffer as soon as possible.
Methods
impl CFixedString
[src]
fn new<T: Into<Box<[u8]>>>(t: T) -> CFixedString
[src]
Construct a new fixed-length C string from a byte slice The first null byte terminates the string, but the length of the slice determines the limit of this fixed-size string.
fn with_limit(limit: usize) -> CFixedString
[src]
Construct an empty string with the specified limit. The buffer is entirely zero-initialized.
unsafe fn from_raw_parts(ptr: *mut c_char, limit: usize) -> CFixedString
[src]
Retakes ownership of a CFixedString that was transferred to C.
Safety
This should only ever be called with a pointer and limit that was earlier obtained from a CFixedString. The previous string must have been forgotten to ensure that the memory has not already been freed.
fn into_string(self) -> Result<String, IntoStringError>
[src]
Converts the CFixedString into a String if it contains valid Unicode data.
On failure, ownership of the original CFixedString is returned.
fn into_c_string(self) -> CString
[src]
Converts the CFixedString into a CString. If necessary, the buffer will be extended to make room for a final null byte. If the buffer does not need to be extended, no allocation will be performed.
fn into_bytes(self) -> Vec<u8>
[src]
Converts the CFixedString into a byte buffer. The length of the buffer will equal the length of the string up to but not including the first null byte. The capacity of the buffer will equal the limit of the CFixedString.
fn into_bytes_full(self) -> Vec<u8>
[src]
Converts the CFixedString into a byte buffer. The length of the buffer will equal the limit of the CFixedString. The buffer may contain garbage values after the first null byte.
fn as_c_fixed_str(&self) -> &CFixedStr
[src]
Extracts a CFixedStr slice containing the entire buffer.
fn as_c_fixed_str_mut(&mut self) -> &mut CFixedStr
[src]
Extracts a mutable CFixedStr slice containing the entire buffer.
fn into_boxed_c_fixed_str(self) -> Box<CFixedStr>
[src]
Converts this CFixedString into a boxed CFixedStr
Methods from Deref<Target = CFixedStr>
fn as_ptr(&self) -> *const c_char
[src]
Returns the inner pointer to this CFixedStr.
Safety
It is your responsibility to make sure the underlying memory is not freed to early.
fn as_mut_ptr(&mut self) -> *mut c_char
[src]
Returns the inner pointer to this mutable CFixedStr.
Safety
It is your responsibility to make sure the underlying memory is not freed to early.
fn limit(&self) -> usize
[src]
Returns the limit of this CFixedStr. This corresponds to the longest possible string that could be stored here.
fn len(&self) -> usize
[src]
Returns the length of the CFixedStr. This operation takes linear time.
fn to_bytes(&self) -> &[u8]
[src]
Coverts this CFixedStr to a byte slice. The length of the slice is equal to the length of the string up to but not including the first null byte.
fn to_bytes_mut(&mut self) -> &mut [u8]
[src]
Coverts this CFixedStr to a mutable byte slice. The length of the slice is equal to the length of the string up to but not including the first null byte.
fn to_bytes_extended(&self) -> &[u8]
[src]
Coverts this CFixedStr to a byte slice. The length of the slice is equal to the length of the string up to and including the first null byte, if it exists.
fn to_bytes_mut_extended(&mut self) -> &mut [u8]
[src]
Coverts this CFixedStr to a mutable byte slice. The length of the slice is equal to the length of the string up to and including the first null byte, if it exists.
fn as_bytes_full(&self) -> &[u8]
[src]
Coverts this CFixedStr to a byte slice. The length of the slice is equal to the limit of the CFixedStr.
fn as_bytes_mut_full(&mut self) -> &mut [u8]
[src]
Coverts this CFixedStr to a mutable byte slice. The length of the slice is equal to the limit of the CFixedStr.
fn to_str(&self) -> Result<&str, Utf8Error>
[src]
Yields a &str slice if the CFixedStr contains valid UTF-8.
This function will calculate the length of this string and check for UTF-8 validity, and then return the &str if it's valid.
fn to_string_lossy(&self) -> Cow<str>
[src]
Converts a CFixedStr into a Cow
This function will calculate the length of this string and then return the resulting
slice as a Cow<str>
, replacing any invalid UTF-8 sequences with U+FFFD REPLACEMENT CHARACTER
.
fn to_c_str(&self) -> Cow<CStr>
[src]
Converts a CFixedStr into a Cow
This function will calculate the length of this string, and then ensure it has a
terminating null byte. If a null byte is already present, the Borrowed
variant
can be returned.
Trait Implementations
impl Drop for CFixedString
[src]
impl Deref for CFixedString
[src]
type Target = CFixedStr
The resulting type after dereferencing.
fn deref(&self) -> &CFixedStr
[src]
Dereferences the value.
impl DerefMut for CFixedString
[src]
impl Debug for CFixedString
[src]
impl Clone for CFixedString
[src]
fn clone(&self) -> Self
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Hash for CFixedString
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialEq for CFixedString
[src]
fn eq(&self, other: &CFixedString) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Eq for CFixedString
[src]
impl PartialOrd for CFixedString
[src]
fn partial_cmp(&self, other: &CFixedString) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for CFixedString
[src]
fn cmp(&self, other: &CFixedString) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl Default for CFixedString
[src]
fn default() -> CFixedString
[src]
Returns the "default value" for a type. Read more
impl Borrow<CFixedStr> for CFixedString
[src]
impl<'a> From<&'a CFixedStr> for CFixedString
[src]
fn from(s: &'a CFixedStr) -> CFixedString
[src]
Performs the conversion.
impl Index<RangeFull> for CFixedString
[src]
type Output = CFixedStr
The returned type after indexing.
fn index(&self, _index: RangeFull) -> &CFixedStr
[src]
Performs the indexing (container[index]
) operation.
impl IndexMut<RangeFull> for CFixedString
[src]
fn index_mut(&mut self, _index: RangeFull) -> &mut CFixedStr
[src]
Performs the mutable indexing (container[index]
) operation.