Added str/string variation to add table.
This commit is contained in:
		@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user