1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#![deny(missing_docs)]
//! This is a create for all the datatypes used across the whole project
use binary_utils::Result;
/// This trait is implemented by enums to be used in the artificial `Enum` struct
pub trait ImportantEnumTrait : Sized {
/// This function creates a new instance of `Self` where data is the offset of the Option
///
/// # Arguments
///
/// `data` - id of the version
///
/// # example
///
/// ```rust
/// enum Example {
/// A,
/// B
/// }
/// impl datatypes::ImportantEnumTrait for Example {
/// fn new(data: u64) -> binary_utils::Result<Self> {
/// match data {
/// 0 => Ok(Self::A),
/// 1 => Ok(Self::B),
/// _ => Err(binary_utils::Error::InvalidId),
/// }
/// }
/// }
/// #[test]
/// fn test() {
/// let a = Example::new(0);
/// assert!(a, Ok(Example::A));
/// let b = Example::new(2);
/// assert!(b, Err(Error::InvalidId));
/// }
fn new(data: u64) -> Result<Self>;
}
mod basic_datatypes;
mod string_based;
mod complex_datatypes;
pub use basic_datatypes::*;
pub use string_based::*;
pub use complex_datatypes::*;
// INFO: the unused warnings are intended to see which datatype are missing implementations
/// A trait implemented by types to provide a `new` and `get_value` function
pub trait ImportantFunctions {
/// The type needed to construct the type
type InputType;
/// The type returned by `get_value`
type ReturnType;
/// A function that constructs a new instance of the type
fn new(data: Self::InputType) -> Self;
/// A function that returns the hold data
fn get_value(&self) -> Self::ReturnType;
}
/// A trait needed for enum operations, implemented by types that have to be converted to `u64`
pub trait GetU64 {
/// A function to get the hold value as `u64`
fn get_u64(&self) -> u64;
}