Completed the trip to client and back.

This commit is contained in:
2025-04-02 22:10:16 -04:00
parent 3355358ac5
commit 311a3293cd
4 changed files with 101 additions and 29 deletions

View File

@ -8,6 +8,15 @@ pub enum Field {
Uuid(Uuid),
}
impl Field {
pub fn to_uuid(&self) -> Result<Uuid, String> {
match self {
Field::Uuid(data) => Ok(data.clone()),
_ => Err("not a uuid".to_string()),
}
}
}
impl From<String> for Field {
fn from(value: String) -> Self {
match Uuid::try_from(value.as_str()) {
@ -121,4 +130,24 @@ mod fields {
let input: Field = result.clone().into();
assert_eq!(input.to_string(), result);
}
#[test]
fn field_to_uuid() {
let id = Uuid::new_v4();
let field: Field = id.into();
match field.to_uuid() {
Ok(result) => assert_eq!(result, id),
Err(_) => unreachable!("did not convert to uuid"),
}
}
#[test]
fn not_uuid_field_to_uuid() {
let text = "Not a uuid.";
let field: Field = text.into();
match field.to_uuid() {
Ok(_) => unreachable!("should return an error"),
Err(_) => {},
}
}
}