[][src]Struct fixed_len_str_example::fixed_str12::FixedStr12

#[repr(transparent)]
pub struct FixedStr12 {
    pub array: [u8; 12],
}

A fixed length string with a length of 12.

Fields

array: [u8; 12]

Methods

impl FixedStr12[src]

pub fn new(array: [u8; 12]) -> Result<Self, Utf8Error>[src]

Creates an FixedStr12 from an array,returning an error at invalid utf8.

pub const unsafe fn new_unchecked(array: [u8; 12]) -> Self[src]

Creates an FixedStr12 without checking if the bytes are valid utf8.

Safety

Ensure to only use this method with valid utf8.

pub fn as_bytes(&self) -> &[u8][src]

Borrow the internal array as an slice.

pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8][src]

Borrow the internal array as a mutable slice.

Safety

This is unsafe due to allow modifications that can produce invalid utf8.

pub fn fill_char(&mut self, character: char)[src]

Fill the last spaces in zero of the buffer with a determinated character.Useful when constructing the array with all bytes in zero and then filling them in an incremental way.

Panics

This will panic on debug if the zero spaces are not sufficient for the non-zero spaces of the character interpreted as \[u8; 4\].

pub fn fill_str(&mut self, s: &str)[src]

Fill the last spaces in zero of the buffer with a determinated string.Useful when constructing the array with all bytes in zero and then filling them in an incremental way.

Panics

This will panic on debug if the zero spaces are not sufficient for the non-zero spaces of the string interpreted as &\[u8\].

pub fn into_vec(self) -> Vec<u8>[src]

Convert the FixedStr12 into a vector of bytes.

pub fn into_string(self) -> String[src]

Turn the FixedStr12 into a string,moving the bytes.

pub fn from_vec(vec: Vec<u8>) -> FixedStr12[src]

Construct a FixedStr12 from a vector of bytes,truncating or pushing zeroes to adjust the size to 12.

Using this function with multi-byte characters can easely produce an unexpected value.

pub fn from_string(string: String) -> FixedStr12[src]

Construct a FixedStr12 from a String,truncating or pushing zeroes to adjust the size to 12.

Using this function with multi-byte characters can easely produce an unexpected value.

pub unsafe fn from_str_unchecked(s: &str) -> FixedStr12[src]

Construct a FixedStr12 from a str,without checking if it has length 12.

Safety

This will trigger UB on str's with length different than 12.

Trait Implementations

impl AsMut<str> for FixedStr12[src]

impl AsRef<str> for FixedStr12[src]

impl Borrow<str> for FixedStr12[src]

impl BorrowMut<str> for FixedStr12[src]

impl Clone for FixedStr12[src]

impl Debug for FixedStr12[src]

impl Default for FixedStr12[src]

impl Deref for FixedStr12[src]

type Target = str

The resulting type after dereferencing.

impl DerefMut for FixedStr12[src]

impl<'de> Deserialize<'de> for FixedStr12[src]

Only expanded in the original crate with the feature "serde_support" enabled.

impl Display for FixedStr12[src]

impl Eq for FixedStr12[src]

impl<'_> From<&'_ str> for FixedStr12[src]

fn from(s: &str) -> Self[src]

Construct a FixedStr12 from a str,if it is greater it take 12 bytes,if it is smaller it will leave the remanining spaces of the FixedStr12 in zero.

Panics

This will panic if the length of s is greater than 12 on debug.

impl From<[u8; 12]> for FixedStr12[src]

impl From<String> for FixedStr12[src]

impl From<Vec<u8>> for FixedStr12[src]

impl Hash for FixedStr12[src]

impl Index<Range<usize>> for FixedStr12[src]

type Output = str

The returned type after indexing.

impl Index<RangeFrom<usize>> for FixedStr12[src]

type Output = str

The returned type after indexing.

impl Index<RangeFull> for FixedStr12[src]

type Output = str

The returned type after indexing.

impl Index<RangeInclusive<usize>> for FixedStr12[src]

type Output = str

The returned type after indexing.

impl Index<RangeTo<usize>> for FixedStr12[src]

type Output = str

The returned type after indexing.

impl Index<RangeToInclusive<usize>> for FixedStr12[src]

type Output = str

The returned type after indexing.

impl IndexMut<Range<usize>> for FixedStr12[src]

impl IndexMut<RangeFrom<usize>> for FixedStr12[src]

impl IndexMut<RangeFull> for FixedStr12[src]

impl IndexMut<RangeInclusive<usize>> for FixedStr12[src]

impl IndexMut<RangeTo<usize>> for FixedStr12[src]

impl IndexMut<RangeToInclusive<usize>> for FixedStr12[src]

impl Ord for FixedStr12[src]

impl<'_> PartialEq<&'_ str> for FixedStr12[src]

impl PartialEq<FixedStr12> for FixedStr12[src]

impl PartialEq<str> for FixedStr12[src]

impl PartialOrd<FixedStr12> for FixedStr12[src]

impl Serialize for FixedStr12[src]

Only expanded in the original crate with the feature "serde_support" enabled.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.