Skip to content

Porting eq_null trait to diesel 2.0.0 #2785

Answered by ensc
ensc asked this question in Q&A
Discussion options

You must be logged in to vote

fwiw, trick was to constrain the associated IsNull type and the final solution is

pub trait EqNull
where
    Self: diesel::expression_methods::ExpressionMethods + Clone,
    Self::SqlType: diesel::sql_types::SqlType<IsNull = is_nullable::IsNullable>,
{
    #[allow(clippy::type_complexity)]
    fn eq_null<U>(self, v: Option<U>) ->
	Or<And<BoolBound, IsNull<Self>>,
	   And<BoolBound, Eq<Self, AsExprOf<Option<U>, Self::SqlType>>, Nullable<Bool>>,
	   Nullable<Bool>>
    where
	Option<U>: diesel::expression::AsExpression<Self::SqlType>,
    {
	use diesel::{ IntoSql, BoolExpressionMethods };

	let fn_bool = |v: bool| v.into_sql::<Bool>();

	fn_bool(v.is_none()).and(self.clone().is_null())
	    .

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@ensc
Comment options

@weiznich
Comment options

Comment options

You must be logged in to vote
2 replies
@weiznich
Comment options

@ensc
Comment options

Answer selected by ensc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants