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;