2024-02-21 14:24:57 +01:00
|
|
|
//! Dynamic data storage and transfer types
|
|
|
|
|
|
|
|
/// Owned data type, for use mostly in outputs and storage
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum OwnedData {
|
|
|
|
String(String),
|
|
|
|
Int(i32),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for OwnedData {
|
|
|
|
fn from(value: String) -> Self {
|
|
|
|
Self::String(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<i32> for OwnedData {
|
|
|
|
fn from(value: i32) -> Self {
|
|
|
|
Self::Int(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Unowned data type, for inputs into runner functions
|
2024-02-21 13:11:31 +01:00
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub enum Data<'a> {
|
|
|
|
String(&'a str),
|
|
|
|
Int(i32),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Data<'_> {
|
2024-02-21 14:24:57 +01:00
|
|
|
/// converts itself to `OwnedData`
|
2024-02-21 13:11:31 +01:00
|
|
|
pub fn to_owned_data(&self) -> OwnedData {
|
|
|
|
match self {
|
|
|
|
Data::String(s) => (*s).to_owned().into(),
|
|
|
|
Data::Int(i) => (*i).into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-21 14:24:57 +01:00
|
|
|
|
2024-02-21 13:11:31 +01:00
|
|
|
impl<'a> From<&'a str> for Data<'a> {
|
|
|
|
fn from(value: &'a str) -> Self {
|
|
|
|
Self::String(value)
|
|
|
|
}
|
|
|
|
}
|
2024-02-21 14:24:57 +01:00
|
|
|
|
2024-02-21 13:11:31 +01:00
|
|
|
impl From<i32> for Data<'_> {
|
|
|
|
fn from(value: i32) -> Self {
|
|
|
|
Self::Int(value)
|
|
|
|
}
|
|
|
|
}
|
2024-02-21 14:24:57 +01:00
|
|
|
|
2024-02-21 13:11:31 +01:00
|
|
|
impl<'a> From<&'a OwnedData> for Data<'a> {
|
|
|
|
fn from(value: &'a OwnedData) -> Self {
|
|
|
|
match value {
|
|
|
|
OwnedData::String(s) => Data::String(s),
|
|
|
|
OwnedData::Int(i) => Data::Int(*i),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|