Skip to main content

Base64String

Struct Base64String 

Source
pub struct Base64String<S: Codec> { /* private fields */ }
Expand description

An owned ordinary Base64 string validated by one exact codec policy.

The value retains the Base64<S> used to encode or validate its text, so its decode methods cannot accidentally select a different alphabet, padding, or trailing-bit policy. Construction either encodes bytes through that codec or validates complete encoded text before ownership is returned. There is deliberately no mutable string access.

This is an ordinary, visibly printable, cloneable value. It performs no cleanup and is not suitable for keys, tokens, passwords, or other secret material. Use the secret module for secret-bearing data.

Implementations§

Source§

impl<S: Codec> Base64String<S>

Source

pub fn encode(codec: Base64<S>, input: &[u8]) -> Result<Self, OneShotError>

Encodes bytes and retains the exact codec policy with the result.

Allocation and length errors use the same contract as Base64::encode_to_string.

Source

pub fn from_string( codec: Base64<S>, encoded: String, ) -> Result<Self, OneShotError>

Validates and adopts an existing owned string without copying it.

The complete string must satisfy the supplied codec’s decode policy. On error, this function consumes and drops the supplied ordinary string.

Source

pub fn parse(codec: Base64<S>, encoded: &str) -> Result<Self, OneShotError>

Validates and copies an encoded string slice into owned storage.

Validation completes before allocation. The copy uses try_reserve_exact, returning OneShotError::AllocationFailed if the reservation cannot be made.

Source

pub const fn codec(&self) -> &Base64<S>

Returns the exact codec retained by this string.

Source

pub fn settings(&self) -> CodecSettings

Returns the retained codec settings.

Source

pub fn as_str(&self) -> &str

Returns the validated encoded text.

Passing this ordinary view to another codec can deliberately discard the retained policy. Use Self::decode to preserve it.

Source

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

Returns the validated encoded bytes.

Passing this ordinary view to another codec can deliberately discard the retained policy. Use Self::decode to preserve it.

Source

pub fn len(&self) -> usize

Returns the encoded byte length.

Source

pub fn is_empty(&self) -> bool

Returns whether the encoded text is empty.

Source

pub fn decode(&self) -> Result<Vec<u8>, OneShotError>

Decodes the validated text with its retained codec.

Source

pub fn decode_with_limit( &self, max_output_len: usize, ) -> Result<Vec<u8>, OneShotError>

Decodes with an exact maximum output length.

Source

pub fn into_string(self) -> String

Consumes the wrapper and returns the validated ordinary string.

The returned String no longer carries the codec policy.

Trait Implementations§

Source§

impl<S: Codec> AsRef<[u8]> for Base64String<S>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<S: Codec> AsRef<str> for Base64String<S>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<S: Clone + Codec> Clone for Base64String<S>

Source§

fn clone(&self) -> Base64String<S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<S: Debug + Codec> Debug for Base64String<S>

Source§

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

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

impl<S: Codec> Display for Base64String<S>

Source§

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

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

impl<S: Eq + Codec> Eq for Base64String<S>

Source§

impl<S: Hash + Codec> Hash for Base64String<S>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<S: PartialEq + Codec> PartialEq for Base64String<S>

Source§

fn eq(&self, other: &Base64String<S>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<S: PartialEq + Codec> StructuralPartialEq for Base64String<S>

Auto Trait Implementations§

§

impl<S> Freeze for Base64String<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Base64String<S>
where S: RefUnwindSafe,

§

impl<S> Send for Base64String<S>

§

impl<S> Sync for Base64String<S>

§

impl<S> Unpin for Base64String<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for Base64String<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for Base64String<S>
where S: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.