amebazii::types::image

Enum EncryptedOr

Source
pub enum EncryptedOr<T> {
    Encrypted(Vec<u8>),
    Plain(T),
}
Expand description

A generic enum representing either encrypted or plain data.

The EncryptedOr enum is used to differentiate between encrypted data and unencrypted (plain) data. It allows to store either type of data in the same structure while providing methods to safely access or mutate the contents, depending on whether the data is encrypted or not.

Variants§

§

Encrypted(Vec<u8>)

Contains encrypted data as a vector of bytes.

§

Plain(T)

Contains plain, unencrypted data of type T.

Implementations§

Source§

impl<T> EncryptedOr<T>

Source

pub fn is_encrypted(&self) -> bool

Returns true if the data is encrypted.

This method allows checking if the current instance of EncryptedOr contains encrypted data.

Source

pub fn is_plain(&self) -> bool

Returns true if the data is plain.

This method allows checking if the current instance of EncryptedOr contains plain (unencrypted) data.

Source

pub fn unwrap(self) -> T

Trait Implementations§

Source§

impl<T> AsMut<[u8]> for EncryptedOr<T>

Source§

fn as_mut(&mut self) -> &mut [u8]

Returns a mutable reference to the encrypted data if available.

§Panics

Panics if the data is plain, as the method expects encrypted data.

Source§

impl<T> AsMut<T> for EncryptedOr<T>

Source§

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

Returns a mutable reference to the plain data if available.

§Panics

Panics if the data is encrypted, as the method expects plain data.

Source§

impl<T> AsRef<[u8]> for EncryptedOr<T>

Source§

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

Returns a reference to the encrypted data if available.

§Panics

Panics if the data is plain, as the method expects encrypted data.

Source§

impl<T> AsRef<T> for EncryptedOr<T>

Source§

fn as_ref(&self) -> &T

Returns a reference to the plain data if available.

§Panics

Panics if the data is encrypted, as the method expects plain data.

Source§

impl<T: Debug> Debug for EncryptedOr<T>

Source§

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

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

impl<T: FromStream> FromStream for EncryptedOr<T>

Source§

fn read_from<R>(&mut self, reader: &mut R) -> Result<(), Error>
where R: Read + Seek,

Reads the data from a stream, either encrypted or plain.

This method deserializes the data from a stream. If the data is encrypted, it reads the encrypted byte vector, otherwise it reads the plain data of type T.

Source§

impl<T: ToStream> ToStream for EncryptedOr<T>

Source§

fn write_to<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek,

Writes the data to a stream, either encrypted or plain.

This method is used to serialize the data into a stream. If the data is encrypted, it writes the encrypted byte vector, otherwise it serializes the plain data of type T.

Source§

impl<T: ToStream> ToStream for EncryptedOr<Vec<T>>

Source§

fn write_to<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek,

Writes the type’s data to a stream. Read more

Auto Trait Implementations§

§

impl<T> Freeze for EncryptedOr<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for EncryptedOr<T>
where T: RefUnwindSafe,

§

impl<T> Send for EncryptedOr<T>
where T: Send,

§

impl<T> Sync for EncryptedOr<T>
where T: Sync,

§

impl<T> Unpin for EncryptedOr<T>
where T: Unpin,

§

impl<T> UnwindSafe for EncryptedOr<T>
where T: 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> 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> ToHex for T
where T: AsRef<[u8]>,

Source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
Source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
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.