Added uuid as a field.
All checks were successful
MoreThanText/morethantext/pipeline/head This commit looks good
All checks were successful
MoreThanText/morethantext/pipeline/head This commit looks good
This commit is contained in:
parent
c511b623fd
commit
6bb7add4b0
53
src/lib.rs
53
src/lib.rs
@ -14,26 +14,42 @@ use std::{
|
||||
ops::Deref,
|
||||
sync::mpsc::{channel, Sender},
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
struct Request;
|
||||
|
||||
#[derive(Clone)]
|
||||
enum Field {
|
||||
Static(String),
|
||||
Uuid(Uuid),
|
||||
}
|
||||
|
||||
impl From<String> for Field {
|
||||
fn from(value: String) -> Self {
|
||||
match Uuid::try_from(value.as_str()) {
|
||||
Ok(data) => return Field::Uuid(data),
|
||||
Err(_) => {},
|
||||
}
|
||||
Field::Static(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Field {
|
||||
fn from(value: &str) -> Self {
|
||||
match Uuid::try_from(value) {
|
||||
Ok(data) => return Field::Uuid(data),
|
||||
Err(_) => {},
|
||||
}
|
||||
Field::Static(value.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Uuid> for Field {
|
||||
fn from(value: Uuid) -> Self {
|
||||
Field::Uuid(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod fields {
|
||||
use super::*;
|
||||
@ -44,6 +60,7 @@ mod fields {
|
||||
for data in entries {
|
||||
match data.clone().into() {
|
||||
Field::Static(result) => assert_eq!(result, data),
|
||||
_ => unreachable!("shouuld have been a static field"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,9 +71,40 @@ mod fields {
|
||||
for data in entries {
|
||||
match data.into() {
|
||||
Field::Static(result) => assert_eq!(result, data),
|
||||
_ => unreachable!("shouuld have been a static field"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uuid_to_field() {
|
||||
let id = Uuid::new_v4();
|
||||
match id.into() {
|
||||
Field::Uuid(result) => assert_eq!(result, id),
|
||||
_ => unreachable!("should have been a uuid field"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uuid_string_to_field() {
|
||||
let id = Uuid::new_v4();
|
||||
let id_string = id.to_string();
|
||||
match id_string.into() {
|
||||
Field::Uuid(result) => assert_eq!(result, id),
|
||||
_ => unreachable!("should have been a uuid field"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uuid_str_to_field() {
|
||||
let id = Uuid::new_v4();
|
||||
let id_string = id.to_string();
|
||||
let id_str = id_string.as_str();
|
||||
match id_str.into() {
|
||||
Field::Uuid(result) => assert_eq!(result, id),
|
||||
_ => unreachable!("should have been a uuid field"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Record {
|
||||
@ -116,6 +164,7 @@ mod records {
|
||||
None => unreachable!("Should return data"),
|
||||
Some(result) => match result {
|
||||
Field::Static(txt) => assert_eq!(txt, data),
|
||||
_ => unreachable!("Should have been static"),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -130,6 +179,7 @@ mod records {
|
||||
None => unreachable!("Should return data"),
|
||||
Some(result) => match result {
|
||||
Field::Static(txt) => assert_eq!(txt, &data),
|
||||
_ => unreachable!("should have been statis"),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -229,7 +279,8 @@ mod responses {
|
||||
match rec.get(col).unwrap() {
|
||||
Field::Static(txt) => {
|
||||
assert_eq!(txt.clone(), fields.next().unwrap().to_string())
|
||||
}
|
||||
},
|
||||
_ => unreachable!("should have been static"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user