特性 `diesel::Expression` 没有为 `IpNetwork` 实现,这是 `&'insert IpNetwork: AsExpression<diesel::sql_types::Inet>`

问题描述 投票:0回答:1

我添加了一个 postgresql 表

net_test
,如下所示:

CREATE TABLE public.net_test (
    net inet NOT NULL,
    id int8 NOT NULL,
    CONSTRAINT net_pk PRIMARY KEY (id)
);

然后添加柴油模型文件,如下所示https://docs.diesel.rs/2.1.x/diesel/pg/sql_types/struct.Inet.html:

use std::fmt::Display;

use serde::Serialize;
use serde::Deserialize;
use crate::model::diesel::dolphin::dolphin_schema::*;
use bigdecimal::BigDecimal;
use chrono::DateTime;
use chrono::offset::Utc;
use ipnetwork::IpNetwork;
    #[derive(Insertable,Queryable,QueryableByName,Debug,Serialize,Deserialize,Default,Clone)]
    #[diesel(table_name = net_test)]
    pub struct NetTest {
        pub net: IpNetwork,
        pub id: i64,
    }

这是架构文件:

table! {
    net_test (id) {
        net -> Inet,
        id -> Int8,
    }
}

当我编译项目时,显示如下错误:

the trait `diesel::Expression` is not implemented for `IpNetwork`, which is required by `&'insert IpNetwork: AsExpression<diesel::sql_types::Inet>`

我应该怎么做才能解决这个问题?这是柴油依赖配置:

diesel = { version = "2.2.1", features = [
    "postgres",
    "64-column-tables",
    "chrono",
    "serde_json",
    "numeric",
    "ipnet-address"
] }
rust rust-diesel
1个回答
0
投票

启用

"network-address"
功能。
"ipnet-address"
功能用于启用对
ipnet
类型的支持,但您没有使用该板条箱;您正在使用
ipnetwork
板条箱。

© www.soinside.com 2019 - 2024. All rights reserved.