下面是我的SQL结构:
CREATE TABLE IF NOT EXISTS passwords
(
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
username TEXT NOT NULL,
password TEXT NOT NULL
);
字符串
当我运行以下代码时:
struct Password {
id: u32,
title: String,
username: String,
password: String,
}
let items = self.client.query("SELECT * FROM passwords", &[]).unwrap().iter().map(|row| {
let password = Password::new_with_id(
row.get("id"),
row.get("title"),
row.get("username"),
row.get("password"),
);
password
}).collect();
型
我得到以下错误:
thread 'main' panicked at C:\Users\k\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-postgres-0.7.10\src\row.rs:151:25:
error retrieving column id: error deserializing column 0: cannot convert between the Rust type `u32` and the Postgres type `int4`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\PaTUI.exe` (exit code: 101)
型
如何在Posterre类型int4
和Rust类型u32
之间成功转换?
1条答案
按热度按时间zvokhttg1#
tokio_postgres
使用postgres_types
,它将int4
定义为i32
。