From d790ad74d580613e4b9db5ed33d58b3730a21409 Mon Sep 17 00:00:00 2001 From: Leo Valais Date: Thu, 26 Dec 2024 17:34:57 +0100 Subject: [PATCH] editoast: change Model traits CreateBatch,WithKey to use editoast_models::Error Signed-off-by: Leo Valais --- .../src/model/codegen/create_batch_impl.rs | 2 +- .../src/model/codegen/create_batch_with_key_impl.rs | 2 +- editoast/src/models/prelude/create.rs | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/editoast/editoast_derive/src/model/codegen/create_batch_impl.rs b/editoast/editoast_derive/src/model/codegen/create_batch_impl.rs index d1684fb2a56..1fda7c9dcd8 100644 --- a/editoast/editoast_derive/src/model/codegen/create_batch_impl.rs +++ b/editoast/editoast_derive/src/model/codegen/create_batch_impl.rs @@ -58,7 +58,7 @@ impl ToTokens for CreateBatchImpl { >( conn: &mut editoast_models::DbConnection, values: I, - ) -> crate::error::Result { + ) -> std::result::Result { use crate::models::Model; use #table_mod::dsl; use std::ops::DerefMut; diff --git a/editoast/editoast_derive/src/model/codegen/create_batch_with_key_impl.rs b/editoast/editoast_derive/src/model/codegen/create_batch_with_key_impl.rs index 7d5f8141512..0e9f2bca3ef 100644 --- a/editoast/editoast_derive/src/model/codegen/create_batch_with_key_impl.rs +++ b/editoast/editoast_derive/src/model/codegen/create_batch_with_key_impl.rs @@ -69,7 +69,7 @@ impl ToTokens for CreateBatchWithKeyImpl { >( conn: &mut editoast_models::DbConnection, values: I, - ) -> crate::error::Result { + ) -> std::result::Result { use crate::models::Identifiable; use crate::models::Model; use std::ops::DerefMut; diff --git a/editoast/src/models/prelude/create.rs b/editoast/src/models/prelude/create.rs index e4509d4e6ae..0dea1e88750 100644 --- a/editoast/src/models/prelude/create.rs +++ b/editoast/src/models/prelude/create.rs @@ -1,10 +1,10 @@ use std::fmt::Debug; +use std::result::Result; use editoast_models::model; use editoast_models::DbConnection; use crate::error::EditoastError; -use crate::error::Result; /// Describes how a [Model](super::Model) can be created in the database /// @@ -14,14 +14,14 @@ use crate::error::Result; pub trait Create: Sized { /// Creates a new row in the database with the values of the changeset and /// returns the created model instance - async fn create(self, conn: &mut DbConnection) -> std::result::Result; + async fn create(self, conn: &mut DbConnection) -> Result; /// Just like [Create::create] but discards the error if any and returns `Err(fail())` instead async fn create_or_fail, F: FnOnce() -> E + Send>( self, conn: &'async_trait mut DbConnection, fail: F, - ) -> std::result::Result { + ) -> Result { match self.create(conn).await { Ok(obj) => Ok(obj), Err(_) => Err(fail()), @@ -56,7 +56,7 @@ where >( conn: &mut DbConnection, values: I, - ) -> Result; + ) -> Result; } /// Describes how a [Model](super::Model) can be created in the database given a batch of its changesets @@ -80,5 +80,5 @@ where >( conn: &mut DbConnection, values: I, - ) -> Result; + ) -> Result; }