Added str/string variation to add table.

This commit is contained in:
Jeff Baskin 2022-08-06 12:38:58 -04:00
parent 07fc00fa93
commit 15ee9f7fa9
1 changed files with 14 additions and 4 deletions

View File

@ -16,12 +16,16 @@ impl MoreThanText {
}
}
pub async fn new_table(&self, name: &str) -> Result<Table, MTTError> {
pub async fn new_table<S>(&self, tname: S) -> Result<Table, MTTError>
where
S: Into<String>,
{
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;