Skip to content

Commit

Permalink
Removed wrong lifetime bound on Condition
Browse files Browse the repository at this point in the history
Closes #70
  • Loading branch information
gammelalf committed Sep 6, 2024
1 parent 4fa6e74 commit 78546df
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Since 0.6.3
- added shorter syntax for `Model::F.field`: `Model.field`
- implemented condition collections for `Option<impl Condition>`

- relaxed / fixed lifetimes
- improved error spans in or! and and!
- removed `AsDbType::from_primitive`
- fixed names of join aliases
Expand Down
2 changes: 1 addition & 1 deletion src/conditions/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
41 changes: 20 additions & 21 deletions src/conditions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand All @@ -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<dyn Condition<'a> + '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<dyn Condition<'a> + 'this>
where
Self: Sized,
Self: Sized + 'this,
{
Arc::new(self)
}
}

/// A [`Condition`] in a box.
pub type BoxedCondition<'a> = Box<dyn Condition<'a>>;

/// A [`Condition`] in an arc.
pub type ArcCondition<'a> = Arc<dyn Condition<'a>>;

impl<'a> Condition<'a> for BoxedCondition<'a> {
impl<'a> Condition<'a> for Box<dyn Condition<'a> + '_> {
fn build(&self, context: &mut QueryContext<'a>) {
self.as_ref().build(context);
}

fn boxed(self) -> BoxedCondition<'a>
fn boxed<'this>(self) -> Box<dyn Condition<'a> + 'this>
where
Self: Sized,
Self: Sized + 'this,
{
self
}

fn arc(self) -> ArcCondition<'a>
fn arc<'this>(self) -> Arc<dyn Condition<'a> + 'this>
where
Self: Sized,
Self: Sized + 'this,
{
Arc::from(self)
}
}
impl<'a> Condition<'a> for ArcCondition<'a> {
impl<'a> Condition<'a> for Arc<dyn Condition<'a> + '_> {
fn build(&self, context: &mut QueryContext<'a>) {
self.as_ref().build(context);
}

fn boxed(self) -> BoxedCondition<'a>
fn boxed<'this>(self) -> Box<dyn Condition<'a> + 'this>
where
Self: Sized,
Self: Sized + 'this,
{
Box::from(self)
}

fn arc(self) -> ArcCondition<'a>
fn arc<'this>(self) -> Arc<dyn Condition<'a> + 'this>
where
Self: Sized,
Self: Sized + 'this,
{
self
}
}
impl<'a> Condition<'a> for &'_ dyn Condition<'a> {
fn build(&self, context: &mut QueryContext<'a>) {
<dyn Condition as Condition>::build(self, context)
}
}

/// A value
///
Expand Down
2 changes: 1 addition & 1 deletion src/crud/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 78546df

Please sign in to comment.