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>
impl<const N: usize> DataArray<N>
Sourcepub fn new(data: String) -> Result<Self, Error>
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 theDataArray
object or an error if the data is invalid.
Sourcepub fn from_string(data: String) -> Result<Self, Error>
pub fn from_string(data: String) -> Result<Self, Error>
Trait Implementations§
Source§impl<'de, const N: usize> Deserialize<'de> for DataArray<N>
impl<'de, const N: usize> Deserialize<'de> for DataArray<N>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<const N: usize> Serialize for DataArray<N>
impl<const N: usize> Serialize for DataArray<N>
Source§fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more