Struct TarFormatString

Source
#[repr(C)]
pub struct TarFormatString<const N: usize> { /* private fields */ }
Expand description

Base type for strings embedded in a Tar header. The length depends on the context. The returned string is likely to be UTF-8/ASCII, which is verified by getters, such as TarFormatString::as_str.

An optionally null terminated string. The contents are either:

  1. A fully populated string with no null termination or
  2. A partially populated string where the unused bytes are zero.

Implementations§

Source§

impl<const N: usize> TarFormatString<N>

A Tar format string is a fixed length byte array containing UTF-8 bytes. This string will be null terminated if it doesn’t fill the entire array.

Source

pub const fn new(bytes: [u8; N]) -> Self

Constructor.

Source

pub const fn is_empty(&self) -> bool

True if the is string empty (ignoring NULL bytes).

Source

pub fn size(&self) -> usize

Returns the length of the payload in bytes. This is either the full capacity N or the data until the first NULL byte.

Source

pub fn as_str(&self) -> Result<&str, Utf8Error>

Returns a str ref without terminating or intermediate NULL bytes. The string is truncated at the first NULL byte, in case not the full length was used.

Source

pub fn as_str_until_first_space(&self) -> Result<&str, Utf8Error>

Wrapper around Self::as_str that stops as soon as the first space is found. This is necessary to properly parse certain Tar-style encoded numbers. Some ustar implementations pad spaces which prevents the proper parsing as number.

Source

pub fn append<const S: usize>(&mut self, other: &TarFormatString<S>)

Append to end of string. Panics if there is not enough capacity.

Trait Implementations§

Source§

impl<const N: usize> Clone for TarFormatString<N>

Source§

fn clone(&self) -> TarFormatString<N>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for TarFormatString<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> PartialEq for TarFormatString<N>

Source§

fn eq(&self, other: &TarFormatString<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> Copy for TarFormatString<N>

Source§

impl<const N: usize> Eq for TarFormatString<N>

Source§

impl<const N: usize> StructuralPartialEq for TarFormatString<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for TarFormatString<N>

§

impl<const N: usize> RefUnwindSafe for TarFormatString<N>

§

impl<const N: usize> Send for TarFormatString<N>

§

impl<const N: usize> Sync for TarFormatString<N>

§

impl<const N: usize> Unpin for TarFormatString<N>

§

impl<const N: usize> UnwindSafe for TarFormatString<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.