Enum cfixed_string::CFixedString[][src]

pub enum CFixedString {
    Local {
        s: [c_char; 512],
        len: usize,
    },
    Heap {
        s: CString,
        len: usize,
    },
}
Expand description

This is a C String abstractions that presents a CStr like interface for interop purposes but tries to be little nicer by avoiding heap allocations if the string is within the generous bounds (512 bytes) of the statically sized buffer. Strings over this limit will be heap allocated, but the interface outside of this abstraction remains the same.

Variants

Local

Fields of Local

s: [c_char; 512]len: usize
Heap

Fields of Heap

s: CStringlen: usize

Implementations

Creates an empty CFixedString, this is intended to be used with write! or the fmt::Write trait

Create from str

Returns the pointer to be passed down to the C code

Returns true if the string has been heap allocated

Converts a CFixedString into a Cow<str>.

This function will calculate the length of this string (which normally requires a linear amount of work to be done) and then return the resulting slice as a Cow<str>, replacing any invalid UTF-8 sequences with U+FFFD REPLACEMENT CHARACTER. If there are no invalid UTF-8 sequences, this will merely return a borrowed slice.

Convert back to str. Unsafe as it uses from_utf8_unchecked

Trait Implementations

Performs the conversion.

Performs the conversion.

Immutably borrows from an owned value. Read more

Immutably borrows from an owned value. Read more

The resulting type after dereferencing.

Dereferences the value.

Performs the conversion.

Performs the conversion.

Writes a string slice into this writer, returning whether the write succeeded. Read more

Writes a char into this writer, returning whether the write succeeded. Read more

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.