diff --git a/src/appwrite.rs b/src/appwrite.rs index f834905..3aef545 100644 --- a/src/appwrite.rs +++ b/src/appwrite.rs @@ -22,7 +22,7 @@ impl APVariables { user_id: &str, ) -> Result { let client = reqwest::Client::new(); - let url = format!("{}/users/{}/sessions", self.endpoint, user_id); + let url = format!("{}/users/{user_id}/sessions", self.endpoint); let response = client .get(url) .header("X-Appwrite-Key", self.api_key.clone()) diff --git a/src/db/mod.rs b/src/db/mod.rs index 2ddf33a..8d0a9ec 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -47,10 +47,7 @@ impl std::fmt::Display for DatabaseError { impl IntoFieldError for DatabaseError { fn into_field_error(self) -> juniper::FieldError { let short = self.short; - FieldError::new( - self.long, - graphql_value!({ "error": short }), - ) + FieldError::new(self.long, graphql_value!({ "error": short })) } } @@ -88,7 +85,7 @@ impl Database { { self.conn.get().map_err(|e| { DatabaseError::new( - format!("Failed to connect to database: {:?}", e), + format!("Failed to connect to database: {e:?}"), "Database connection error", ) }) @@ -99,11 +96,11 @@ impl Database { languages .load::(&mut self.conn()?) .map_err(|e| { - info!("Failed to retrieve languages from database: {:?}", e); + info!("Failed to retrieve languages from database: {e:?}"); }) .map_err(|e| { DatabaseError::new( - format!("Failed to retrieve languages: {:?}", e), + format!("Failed to retrieve languages: {e:?}"), "Failed to retrieve languages", ) }) @@ -113,7 +110,7 @@ impl Database { use self::schema::users::dsl::users; users.load::(&mut self.conn()?).map_err(|e| { DatabaseError::new( - format!("Failed to retrieve languages: {:?}", e), + format!("Failed to retrieve languages: {e:?}"), "Failed to retrieve languages", ) }) @@ -125,13 +122,12 @@ impl Database { ) -> Result, DatabaseError> { use self::schema::languages::dsl; dsl::languages - .filter(dsl::name.ilike(format!("%{}%", query))) + .filter(dsl::name.ilike(format!("%{query}%"))) .load::(&mut self.conn()?) .map_err(|e| { DatabaseError::new( format!( - "Failed to retrieve languages with query {}: {:?}", - query, e + "Failed to retrieve languages with query {query}: {e:?}" ), "Failed to retrieve languages", ) @@ -141,13 +137,12 @@ impl Database { pub fn find_user(&self, query: &str) -> Result, DatabaseError> { use self::schema::users::dsl; dsl::users - .filter(dsl::username.ilike(format!("%{}%", query))) + .filter(dsl::username.ilike(format!("%{query}%"))) .load::(&mut self.conn()?) .map_err(|e| { DatabaseError::new( format!( - "Failed to retrieve users with query {}: {:?}", - query, e + "Failed to retrieve users with query {query}: {e:?}" ), "Failed to retrieve languages", ) @@ -169,8 +164,7 @@ impl Database { Err(Error::NotFound) => Ok(None), Err(e) => Err(DatabaseError::new( format!( - "Failed to find language {} belonging to {}: {:?}", - name, owner, e + "Failed to find language {name} belonging to {owner}: {e:?}" ), "Database error", )), @@ -183,10 +177,7 @@ impl Database { Ok(val) => Ok(Some(val)), Err(Error::NotFound) => Ok(None), Err(e) => Err(DatabaseError::new( - format!( - "Failed to retrieve user {} from database: {:?}", - id, e - ), + format!("Failed to retrieve user {id} from database: {e:?}"), "Database Error", )), } @@ -202,14 +193,14 @@ impl Database { match insert_into(users).values(user.clone()).execute( &mut self.conn().map_err(|e| { DatabaseError::new( - format!("Failed to connect to the database: {:?}", e), + format!("Failed to connect to the database: {e:?}"), "Connection error", ) })?, ) { Ok(_) => Ok(user), Err(e) => Err(DatabaseError { - long: format!("Failed to insert user {:?}: {:?}", user, e), + long: format!("Failed to insert user {user:?}: {e:?}"), short: "Data insertion error".to_string(), }), } @@ -222,7 +213,7 @@ impl Database { { Ok(_) => Ok(()), Err(e) => Err(DatabaseError::new( - format!("Failed to delete user {}: {:?}", id, e), + format!("Failed to delete user {id}: {e:?}"), "User deletion error", )), } @@ -234,10 +225,7 @@ impl Database { Ok(val) => Ok(Some(val)), Err(Error::NotFound) => Ok(None), Err(e) => Err(DatabaseError::new( - format!( - "Failed to retrieve word {} from database: {:?}", - id, e - ), + format!("Failed to retrieve word {id} from database: {e:?}"), "Database Error", )), } @@ -256,8 +244,7 @@ impl Database { .map_err(|e| { DatabaseError::new( format!( - "Failed to retrieve word {} from language {}: {:?}", - word, language, e + "Failed to retrieve word {word} from language {language}: {e:?}" ), "Failed to retrieve languages", ) @@ -272,14 +259,12 @@ impl Database { use self::schema::words::dsl; dsl::words .filter(dsl::language.eq(language)) - .filter(dsl::norm.ilike(format!("%{}%", query))) + .filter(dsl::norm.ilike(format!("%{query}%"))) .load::(&mut self.conn()?) .map_err(|e| { DatabaseError::new( format!( - "Failed to retrieve words from language {} with query {}: {:?}", - language, - query, e + "Failed to retrieve words from language {language} with query {query}: {e:?}" ), "Failed to retrieve languages", ) diff --git a/src/db/models/languages.rs b/src/db/models/languages.rs index 27fb11f..b0eefbf 100644 --- a/src/db/models/languages.rs +++ b/src/db/models/languages.rs @@ -147,8 +147,7 @@ impl Language { .map_err(|e| { DatabaseError::new( format!( - "Failed to retrieve language translations: {:?}", - e + "Failed to retrieve language translations: {e:?}" ), "Database reading failure", ) @@ -160,7 +159,7 @@ impl Language { }) .collect::>()), Err(e) => Err(DatabaseError::new( - format!("Failed to connect to the database: {:?}", e), + format!("Failed to connect to the database: {e:?}"), "Database connection failure", ) .into()), @@ -218,14 +217,14 @@ impl Language { .map_err(|e| { DatabaseError::new( format!( - "Failed to retrieve owner {} of language {}: {:?}", - self.owner, self.name, e + "Failed to retrieve owner {} of language {}: {e:?}", + self.owner, self.name ), "Database reading error", ) })?), Err(e) => Err(DatabaseError::new( - format!("Failed to connect to the database: {:?}", e), + format!("Failed to connect to the database: {e:?}"), "Database connection failure", ) .into()), diff --git a/src/db/models/users.rs b/src/db/models/users.rs index 0d0c08a..ed85325 100644 --- a/src/db/models/users.rs +++ b/src/db/models/users.rs @@ -28,7 +28,7 @@ impl User { use super::super::schema::{userfollows, users}; let conn = &mut context.db.conn().map_err(|e| { DatabaseError::new( - format!("Failed to connect to database: {:?}", e), + format!("Failed to connect to database: {e:?}"), "Database connection error", ) })?; @@ -38,8 +38,7 @@ impl User { .map_err(|e| { DatabaseError::new( format!( - "Failed to retrieve user follows from database: {:?}", - e + "Failed to retrieve user follows from database: {e:?}" ), "Database reading error", ) @@ -52,9 +51,8 @@ impl User { Ok(val) => Some(val), Err(e) => { let err = DatabaseError::new( - format!("Failed to retrieve user {} from database: {:?}", - f.following.clone(), - e), + format!("Failed to retrieve user {} from database: {e:?}", + f.following.clone()), "Database reading error"); debug!("{}", err); None diff --git a/src/db/models/words.rs b/src/db/models/words.rs index 114a028..8406c0c 100644 --- a/src/db/models/words.rs +++ b/src/db/models/words.rs @@ -76,7 +76,7 @@ impl Word { .load::(conn) .map_err(|e| { DatabaseError::new( - format!("Failed to retrieve word relations: {:?}", e), + format!("Failed to retrieve word relations: {e:?}"), "Database reading failed", ) })? @@ -87,7 +87,7 @@ impl Word { }) .collect::>()), Err(e) => Err(DatabaseError::new( - format!("Failed to connect to the database: {:?}", e), + format!("Failed to connect to the database: {e:?}"), "Database connection error", )), } diff --git a/src/graphql/query.rs b/src/graphql/query.rs index e96d34a..d3056fa 100644 --- a/src/graphql/query.rs +++ b/src/graphql/query.rs @@ -120,7 +120,7 @@ impl Query { .find_word(uuid, query.as_str()) .map_err(Into::into), Err(e) => Err(DatabaseError::new( - format!("Failed to convert {} to a UUID: {:?}", language, e), + format!("Failed to convert {language} to a UUID: {e:?}"), "Conversion Error", ) .into()), @@ -147,7 +147,7 @@ impl Query { context.db.words(uuid, word.as_str()).map_err(Into::into) } Err(e) => Err(DatabaseError::new( - format!("Failed to convert {} to a UUID: {:?}", language, e), + format!("Failed to convert {language} to a UUID: {e:?}"), "Conversion Error", ) .into()),