Rust 如何在sqlx模型中将枚举的Vec定义为字段

Rust 如何在sqlx模型中将枚举的Vec定义为字段,rust,rust-sqlx,Rust,Rust Sqlx,我正在尝试将Postgres中的数组字段加载到Rust结构,如下所示 使用sqlx::{Pool,PgConnection,PgPool,FromRow}; 使用sqlx::postgres::PgQueryAs; [deriveCopy,Clone,sqlx::Type] [sqlxrename=VARCHAR] [sqlxrename\u all=snake\u案例] 枚举优惠券{ Christmasalecoupon, 新年礼券, } [派生自行,克隆] 结构UserCouponMap{

我正在尝试将Postgres中的数组字段加载到Rust结构,如下所示

使用sqlx::{Pool,PgConnection,PgPool,FromRow}; 使用sqlx::postgres::PgQueryAs; [deriveCopy,Clone,sqlx::Type] [sqlxrename=VARCHAR] [sqlxrename\u all=snake\u案例] 枚举优惠券{ Christmasalecoupon, 新年礼券, } [派生自行,克隆] 结构UserCouponMap{ 酒吧id:i64, 发布用户_id:i64, 酒吧券:Vec, } impl UserCouponMap{ pub async fn get_for_useriddb_pool:pool,user_id:i64->Vec{ 让用户\u优惠券\u映射:Vec=sqlx::query\u asSELECT*来自用户\u优惠券\u映射,其中用户\u id=$1 .binduser\u id .fetch_alldb_池 等候 .获取用户优惠券映射失败; 用户\优惠券\地图 } } [tokio::main] 异步fn获取\u用户\u id用户\u id:i64的\u优惠券\u{ 让pool=PgPool::newpostgresql://asnim@dbhost:5732.await.expected预期展开成功; 让user\u优惠券\u map=UserCouponMap::get\u for\u useridpool,user\u id.wait; } fn干线{ 获取用户id20的优惠券; } 根据这个数组,我已经为优惠券实现了sqlx::Type

不过,编译人员说,有些特性并没有得到满足

   Compiling playground v0.1.0 (/Users/asnimansari/CLionProjects/playground)
error[E0277]: the trait bound `Vec<Coupon>: Type<Postgres>` is not satisfied
  --> src/main.rs:23:14
   |
23 |             .fetch_all(db_pool)
   |              ^^^^^^^^^ the trait `Type<Postgres>` is not implemented for `Vec<Coupon>`
   |
   = help: the following implementations were found:
             <Vec<&[u8]> as Type<Postgres>>
             <Vec<&str> as Type<Postgres>>
             <Vec<(T1, T2)> as Type<Postgres>>
             <Vec<(T1, T2, T3)> as Type<Postgres>>
           and 29 others
   = note: required because of the requirements on the impl of `for<'c> FromRow<'c, PgRow<'c>>` for `UserCouponMap`

error[E0277]: the trait bound `[Coupon]: Type<Postgres>` is not satisfied
  --> src/main.rs:23:14
   |
23 |             .fetch_all(db_pool)
   |              ^^^^^^^^^ the trait `Type<Postgres>` is not implemented for `[Coupon]`
   |
   = help: the following implementations were found:
             <[&[u8]] as Type<Postgres>>
             <[&str] as Type<Postgres>>
             <[(T1, T2)] as Type<Postgres>>
             <[(T1, T2, T3)] as Type<Postgres>>
           and 29 others
   = note: required because of the requirements on the impl of `sqlx::decode::Decode<'_, Postgres>` for `Vec<Coupon>`
   = note: required because of the requirements on the impl of `for<'c> FromRow<'c, PgRow<'c>>` for `UserCouponMap`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`

To learn more, run the command again with --verbose.


sqlx = { version = "0.3.5", default-features = false, features = ["runtime-tokio", "macros", "postgres", "all-type"] }
tokio = { version = "0.2.21", features = ["full"] }