mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2025-09-24 23:41:30 +02:00
prowocessing: apply most basic reviews
This commit is contained in:
parent
734a734f09
commit
b7bc0366c2
6 changed files with 46 additions and 42 deletions
|
@ -1,58 +1,58 @@
|
|||
//! Dynamic data storage and transfer types
|
||||
//! Dynamic data storage and transfer types for use in [`io`]
|
||||
|
||||
/// Owned data type, for use mostly in outputs and storage
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum OwnedData {
|
||||
pub enum Data {
|
||||
String(String),
|
||||
Int(i32),
|
||||
}
|
||||
|
||||
impl From<String> for OwnedData {
|
||||
impl From<String> for Data {
|
||||
fn from(value: String) -> Self {
|
||||
Self::String(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for OwnedData {
|
||||
impl From<i32> for Data {
|
||||
fn from(value: i32) -> Self {
|
||||
Self::Int(value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Unowned data type, for inputs into runner functions
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum Data<'a> {
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum DataRef<'a> {
|
||||
String(&'a str),
|
||||
Int(i32),
|
||||
}
|
||||
|
||||
impl Data<'_> {
|
||||
impl DataRef<'_> {
|
||||
/// converts itself to `OwnedData`
|
||||
pub fn to_owned_data(&self) -> OwnedData {
|
||||
pub fn to_owned_data(&self) -> Data {
|
||||
match self {
|
||||
Data::String(s) => (*s).to_owned().into(),
|
||||
Data::Int(i) => (*i).into(),
|
||||
DataRef::String(s) => (*s).to_owned().into(),
|
||||
DataRef::Int(i) => (*i).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for Data<'a> {
|
||||
impl<'a> From<&'a str> for DataRef<'a> {
|
||||
fn from(value: &'a str) -> Self {
|
||||
Self::String(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for Data<'_> {
|
||||
impl From<i32> for DataRef<'_> {
|
||||
fn from(value: i32) -> Self {
|
||||
Self::Int(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a OwnedData> for Data<'a> {
|
||||
fn from(value: &'a OwnedData) -> Self {
|
||||
impl<'a> From<&'a Data> for DataRef<'a> {
|
||||
fn from(value: &'a Data) -> Self {
|
||||
match value {
|
||||
OwnedData::String(s) => Data::String(s),
|
||||
OwnedData::Int(i) => Data::Int(*i),
|
||||
Data::String(s) => DataRef::String(s),
|
||||
Data::Int(i) => DataRef::Int(*i),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue