#[repr(transparent)]
pub struct StringArray<const N: usize>(_);
Expand description

An array containing a null-terminated string.

Equality / Hashing

For the purposes of comparing and hashing array strings, any characters after the first null terminator are ignored. The below example demonstrates this property with two strings that differ in the characters that come after the first null terminators.

let string1 = StringArray::<3>::new([0x61, 0, 0]);
let string2 = StringArray::<3>::new([0x61, 0, 0x61]);

assert_eq!(string1, string2);

let mut hasher1 = DefaultHasher::new();
string1.hash(&mut hasher1);
let mut hasher2 = DefaultHasher::new();
string2.hash(&mut hasher2);

assert_eq!(hasher1.finish(), hasher2.finish());

Implementations

Constructs a string array from a character array.

Panics
  • characters does not contain a null-terminator

Constructs a string array from a byte string.

If the byte string is longer than N - 1, then the byte string will be truncated to fit inside of the constructed string array (the last character is reserved for a null terminator). The constructed string array will always be null-terminated regardless if the byte string is or is not null-terminated.

Constructs a string array from a borrowed C string.

If the borrowed C string is longer than N - 1, then the borrowed C string will be truncated to fit inside of the constructed string array (the last character is reserved for a null terminator).

Constructs a string array from a pointer to a null-terminated string.

If the null-terminated string is longer than N - 1, then the null-terminated string will be truncated to fit inside of the constructed string array (the last character is reserved for a null terminator).

Safety
  • ptr must be a pointer to a null-terminated string

Gets the underlying character array for this string array.

Gets this string array as a slice of bytes.

Gets this string array as a borrowed C string.

Converts this string array to a UTF-8 string (lossily).

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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 resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

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.