Cannot apply unary operator `!` with Diesel
I am using !
to do a not equal like this:
ChannelRequest { excludeEditorPickChannel, ..} if excludeEditorPickChannel.unwrap_or(0) == 1 => Box::new(!editor_pick.eq(excludeEditorPickChannel)),
When I compile this code it shows an error:
error[E0600]: cannot apply unary operator `!` to type `diesel::expression::operators::Eq<dolphin_schema::rss_sub_source::columns::editor_pick, diesel::expression::bound::Bound<diesel::sql_types::Nullable<Integer>, &std::option::Option<i32>>>`
--> src/service/app/cruise/channel/channel_service.rs:35:114
|
35 | ...unwrap_or(0) == 1 => Box::new(!editor_pick.eq(excludeEditorPickChannel)),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot apply unary operator `!`
For more information about this error, try `rustc --explain E0600`.
warning: `reddwarf-admin` (bin "reddwarf-admin") generated 10 warnings
error: could not compile `reddwarf-admin` due to previous error; 10 warnings emitted
editor_pick
was the diesel table schema column. The table is defined like this:
table! {
rss_sub_source (id) {
id -> Int8,
sub_url -> Varchar,
created_time -> Int8,
updated_time -> Int8,
sub_status -> Int2,
rss_type -> Varchar,
standard_type -> Varchar,
standard_version -> Varchar,
cron -> Varchar,
trigger_count -> Int4,
next_trigger_time -> Nullable<Timestamp>,
sub_name -> Varchar,
last_trigger_time -> Nullable<Timestamptz>,
tags -> Nullable<Array<Int4>>,
source_url -> Nullable<Varchar>,
sub_type -> Nullable<Varchar>,
intro -> Nullable<Varchar>,
remark -> Nullable<Varchar>,
title_hash -> Nullable<Varchar>,
failed_count -> Int4,
lang -> Nullable<Varchar>,
frequency_month -> Nullable<Int4>,
reputation -> Nullable<Int4>,
rep_lastest_refresh_time -> Nullable<Int8>,
scrapy_take_time -> Nullable<Int4>,
follower -> Nullable<Int8>,
censor_status -> Nullable<Int4>,
etag -> Nullable<Varchar>,
last_modified -> Nullable<Varchar>,
editor_pick -> Nullable<Int4>,
fav_icon_url -> Nullable<Varchar>,
dynamic_interval -> Int4,
local_icon_url -> Nullable<Varchar>,
creator -> Int8,
}
}
excludeEditorPickChannel
was the parameter which received by the rust rocket, the excludeEditorPickChannel
define like this:
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
#[allow(non_snake_case)]
pub struct ChannelRequest {
pub userId: Option<i64>,
pub pageNum: Option<i64>,
pub pageSize: Option<i64>,
pub editorPick: Option<i32>,
pub minimalReputation: Option<i32>,
pub excludeEditorPickChannel: Option<i32>
}
Why can't I apply the !
? What should I do to implement the not equal?
Solution 1:
You can use ne
instead of !eq
.