From 74c64890e221ce992eeb2d6289e0a8fd9818bdfd Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Mon, 10 Feb 2025 08:05:59 -0500 Subject: [PATCH] Addded statis field. --- src/data/mod.rs | 4 ++-- src/lib.rs | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/data/mod.rs b/src/data/mod.rs index c62797e..0b2734d 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -4,12 +4,12 @@ pub mod id; mod record; pub mod table; +use super::Message; use std::{ collections::BTreeMap, - sync::mpsc::{Receiver, Sender, channel}, + sync::mpsc::{channel, Receiver, Sender}, thread::spawn, }; -use super::Message; use uuid::Uuid; #[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Clone, Debug)] diff --git a/src/lib.rs b/src/lib.rs index 0c8c0e1..a6e2fa7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,47 @@ use std::sync::mpsc::{channel, Sender}; struct Request; +enum Field { + Static(String), +} + +impl From for Field { + fn from(value: String) -> Self { + Field::Static(value) + } +} + +impl From<&str> for Field { + fn from(value: &str) -> Self { + Field::Static(value.to_string()) + } +} + +#[cfg(test)] +mod fields { + use super::*; + + #[test] + fn string_to_field() { + let entries = ["test1".to_string(), "test2".to_string()]; + for data in entries { + match data.clone().into() { + Field::Static(result) => assert_eq!(result, data), + } + } + } + + #[test] + fn str_to_field() { + let entries = ["test1", "test2"]; + for data in entries { + match data.into() { + Field::Static(result) => assert_eq!(result, data), + } + } + } +} + struct Record; struct Response { @@ -32,7 +73,10 @@ impl Response { 0 } - fn add_header(&mut self, name: S) where S: Into { + fn add_header(&mut self, name: S) + where + S: Into, + { self.headers.push(name.into()); } }