From 78546df0f8b78190c894f8f483b301223e8261a8 Mon Sep 17 00:00:00 2001 From: gammelalf Date: Fri, 6 Sep 2024 21:45:58 +0200 Subject: [PATCH] Removed wrong lifetime bound on `Condition` Closes #70 --- changelog.txt | 1 + src/conditions/collections.rs | 2 +- src/conditions/mod.rs | 41 +++++++++++++++++------------------ src/crud/builder.rs | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/changelog.txt b/changelog.txt index 4033a5f..c57fdb4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -8,6 +8,7 @@ Since 0.6.3 - added shorter syntax for `Model::F.field`: `Model.field` - implemented condition collections for `Option` +- relaxed / fixed lifetimes - improved error spans in or! and and! - removed `AsDbType::from_primitive` - fixed names of join aliases diff --git a/src/conditions/collections.rs b/src/conditions/collections.rs index b28324b..bb80f9e 100644 --- a/src/conditions/collections.rs +++ b/src/conditions/collections.rs @@ -48,7 +48,7 @@ //! } //! ``` -use super::{BoxedCondition, Condition}; +use super::Condition; use crate::internal::query_context::flat_conditions::FlatCondition; use crate::internal::query_context::QueryContext; diff --git a/src/conditions/mod.rs b/src/conditions/mod.rs index 2b25e1d..e7dcb75 100644 --- a/src/conditions/mod.rs +++ b/src/conditions/mod.rs @@ -19,7 +19,7 @@ use crate::internal::query_context::QueryContext; use crate::internal::relation_path::Path; /// Node in a condition tree -pub trait Condition<'a>: 'a + Send + Sync { +pub trait Condition<'a>: Send + Sync { /// Adds this condition to a query context's internal representation /// /// If you're not implementing `Condition`, you'll probably want [`QueryContext::add_condition`]. @@ -30,66 +30,65 @@ pub trait Condition<'a>: 'a + Send + Sync { fn build(&self, context: &mut QueryContext<'a>); /// Convert the condition into a boxed trait object to erase its concrete type - fn boxed(self) -> BoxedCondition<'a> + fn boxed<'this>(self) -> Box + 'this> where - Self: Sized, + Self: Sized + 'this, { Box::new(self) } /// Convert the condition into an arced trait object to erase its concrete type while remaining cloneable - fn arc(self) -> ArcCondition<'a> + fn arc<'this>(self) -> Arc + 'this> where - Self: Sized, + Self: Sized + 'this, { Arc::new(self) } } -/// A [`Condition`] in a box. -pub type BoxedCondition<'a> = Box>; - -/// A [`Condition`] in an arc. -pub type ArcCondition<'a> = Arc>; - -impl<'a> Condition<'a> for BoxedCondition<'a> { +impl<'a> Condition<'a> for Box + '_> { fn build(&self, context: &mut QueryContext<'a>) { self.as_ref().build(context); } - fn boxed(self) -> BoxedCondition<'a> + fn boxed<'this>(self) -> Box + 'this> where - Self: Sized, + Self: Sized + 'this, { self } - fn arc(self) -> ArcCondition<'a> + fn arc<'this>(self) -> Arc + 'this> where - Self: Sized, + Self: Sized + 'this, { Arc::from(self) } } -impl<'a> Condition<'a> for ArcCondition<'a> { +impl<'a> Condition<'a> for Arc + '_> { fn build(&self, context: &mut QueryContext<'a>) { self.as_ref().build(context); } - fn boxed(self) -> BoxedCondition<'a> + fn boxed<'this>(self) -> Box + 'this> where - Self: Sized, + Self: Sized + 'this, { Box::from(self) } - fn arc(self) -> ArcCondition<'a> + fn arc<'this>(self) -> Arc + 'this> where - Self: Sized, + Self: Sized + 'this, { self } } +impl<'a> Condition<'a> for &'_ dyn Condition<'a> { + fn build(&self, context: &mut QueryContext<'a>) { + ::build(self, context) + } +} /// A value /// diff --git a/src/crud/builder.rs b/src/crud/builder.rs index c307eee..3d0e7da 100644 --- a/src/crud/builder.rs +++ b/src/crud/builder.rs @@ -5,7 +5,7 @@ use crate::internal::query_context::QueryContext; use crate::sealed; /// Marker for the generic parameter storing an optional [`Condition`] -pub trait ConditionMarker<'a>: 'a + Send { +pub trait ConditionMarker<'a>: Send { sealed!(trait); /// Calls [`Condition::build`] if `Self: Condition`