prowocessing: add documentation of trait experiment

This commit is contained in:
Schrottkatze 2024-02-21 14:24:57 +01:00
commit 734a734f09
No known key found for this signature in database
9 changed files with 93 additions and 37 deletions

View file

@ -1,3 +1,25 @@
//! 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
#[derive(Clone, Copy)]
pub enum Data<'a> {
String(&'a str),
@ -5,6 +27,7 @@ pub enum Data<'a> {
}
impl Data<'_> {
/// converts itself to `OwnedData`
pub fn to_owned_data(&self) -> OwnedData {
match self {
Data::String(s) => (*s).to_owned().into(),
@ -12,16 +35,19 @@ impl Data<'_> {
}
}
}
impl<'a> From<&'a str> for Data<'a> {
fn from(value: &'a str) -> Self {
Self::String(value)
}
}
impl From<i32> for Data<'_> {
fn from(value: i32) -> Self {
Self::Int(value)
}
}
impl<'a> From<&'a OwnedData> for Data<'a> {
fn from(value: &'a OwnedData) -> Self {
match value {
@ -30,19 +56,3 @@ impl<'a> From<&'a OwnedData> for Data<'a> {
}
}
}
#[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)
}
}