amebazii::conf

Struct DataArray

Source
pub struct DataArray<const N: usize> {
    pub data: [u8; N],
    pub path: Option<String>,
}
Expand description

A struct representing an array of bytes of a fixed size, which can be either loaded from a file or encoded as a hexadecimal string.

Fields§

§data: [u8; N]

The byte array that holds the data.

§path: Option<String>

The optional file path from which the data was loaded (if applicable).

Implementations§

Source§

impl<const N: usize> DataArray<N>

Source

pub fn new(data: String) -> Result<Self, Error>

Creates a new DataArray from a string that is either a file path or a hexadecimal string. If the path exists, it loads the data from the file. Otherwise, it treats the string as a hex string.

§Parameters
  • data: A string which could either be a file path or a hex string.
§Returns
  • A Result containing the DataArray object or an error if the data is invalid.
Source

pub fn from_string(data: String) -> Result<Self, Error>

Creates a DataArray from a hexadecimal string.

§Parameters
  • data: A hexadecimal string to decode into the byte array.
§Returns
  • A Result containing the DataArray object or an error if the data length is invalid.
Source

pub fn load(path: String) -> Result<Self, Error>

Loads the data from a file at the given path.

§Parameters
  • path: The file path to load the data from.
§Returns
  • A Result containing the DataArray object or an error if the data length is invalid.

Trait Implementations§

Source§

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

Source§

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

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

impl<'de, const N: usize> Deserialize<'de> for DataArray<N>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Custom deserialization logic for DataArray. It reads the input as a string, which can either be a file path or a hex string.

§Parameters
  • deserializer: The deserializer used to read the input.
§Returns
  • A Result containing the DataArray object or an error.
Source§

impl<const N: usize> Serialize for DataArray<N>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Custom serialization logic for DataArray. If the data was loaded from a file, it writes the data to the file and serializes the path. If the data was provided as a hex string, it serializes the hex string.

§Parameters
  • serializer: The serializer used to write the output.
§Returns
  • A Result containing the serialized object or an error.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<const N: usize> UnwindSafe for DataArray<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> 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, 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.
Source§

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