when I use the in the rust(1.84.0) model, shows error:
the trait `types::_::_serde::Deserialize<'_>` is not implemented for `IpNetwork`
but I really need Deserialize the model, I can not change the ipnetwork code, how could I do to fixed this issue? This is the dependencies:
ipnetwork = "0.21.1"
this is the model I have defined:
#![allow(unused)]
#![allow(clippy::all)]
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 = users)]
pub struct User {
pub id: i64,
pub nickname: String,
pub avatar_url: String,
pub phone: String,
pub updated_time: i64,
pub created_time: i64,
pub salt: String,
pub pwd: String,
pub sex: i32,
pub level_type: String,
pub phone_region: String,
pub country_code: String,
pub user_status: i32,
pub last_login_time: Option<i64>,
pub first_login_time: Option<i64>,
pub app_id: String,
pub register_time: i64,
pub apple_iap_product_id: Option<String>,
pub auto_renew_product_expire_time_ms: Option<i64>,
pub is_guest: i32,
pub product_id: i32,
pub register_ip: String,
pub reg_ip: Option<IpNetwork>,
}
when I use the in the rust(1.84.0) model, shows error:
the trait `types::_::_serde::Deserialize<'_>` is not implemented for `IpNetwork`
but I really need Deserialize the model, I can not change the ipnetwork code, how could I do to fixed this issue? This is the dependencies:
ipnetwork = "0.21.1"
this is the model I have defined:
#![allow(unused)]
#![allow(clippy::all)]
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 = users)]
pub struct User {
pub id: i64,
pub nickname: String,
pub avatar_url: String,
pub phone: String,
pub updated_time: i64,
pub created_time: i64,
pub salt: String,
pub pwd: String,
pub sex: i32,
pub level_type: String,
pub phone_region: String,
pub country_code: String,
pub user_status: i32,
pub last_login_time: Option<i64>,
pub first_login_time: Option<i64>,
pub app_id: String,
pub register_time: i64,
pub apple_iap_product_id: Option<String>,
pub auto_renew_product_expire_time_ms: Option<i64>,
pub is_guest: i32,
pub product_id: i32,
pub register_ip: String,
pub reg_ip: Option<IpNetwork>,
}
Share
Improve this question
asked Mar 23 at 5:25
DolphinDolphin
39.3k102 gold badges376 silver badges717 bronze badges
1 Answer
Reset to default 2The ipnetwork
crate has a serde
feature which, when enabled, adds Serialize
and Deserialize
implementations on its types. Just enable this feature (cargo add ipnetwork -F serde
).