From 15ee9f7fa90aa5d6cc08d00d4ca3dd9c054ce306 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Sat, 6 Aug 2022 12:38:58 -0400 Subject: [PATCH] Added str/string variation to add table. --- src/morethantext/mod.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index fe57ba9..eca7685 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -16,12 +16,16 @@ impl MoreThanText { } } - pub async fn new_table(&self, name: &str) -> Result { + pub async fn new_table(&self, tname: S) -> Result + where + S: Into, + { let mut tables = self.tables.write().await; - match tables.get(name) { + let name = tname.into(); + match tables.get(&name) { Some(_) => Err(MTTError::new(format!("table {} already exists", name))), None => { - tables.insert(name.to_string(), Table::new().await); + tables.insert(name, Table::new().await); Ok(Table::new().await) } } @@ -41,11 +45,17 @@ mod database { use super::*; #[async_std::test] - async fn create_table() { + async fn create_table_with_str() { let db = MoreThanText::new().await; db.new_table("william").await.unwrap(); } + #[async_std::test] + async fn create_table_with_string() { + let db = MoreThanText::new().await; + db.new_table("marvin".to_string()).await.unwrap(); + } + #[async_std::test] async fn table_names_are_unique() -> Result<(), String> { let db = MoreThanText::new().await;