Crates.io | pg_mapper |
lib.rs | pg_mapper |
version | 0.2.1 |
source | src |
created_at | 2021-12-27 14:27:36.418798 |
updated_at | 2022-03-10 13:04:59.82265 |
description | derive `TryFrom |
homepage | |
repository | https://github.com/malobre/pg_mapper |
max_upload_size | |
id | 503737 |
size | 7,051 |
#[derive(TryFromRow)]
/// This will try to get each column value by name.
#[derive(pg_mapper::TryFromRow)]
struct User {
email: String,
password_digest: String,
}
/// This will try to get each column value by index.
#[derive(pg_mapper::TryFromRow)]
struct Point(i32, i32, i32);
Generates:
impl TryFrom<tokio_postgres::Row> for User {
type Error = tokio_postgres::Error;
fn try_from(row: tokio_postgres::Row) -> Result<Self, Self::Error> {
Ok(Self {
email: row.try_get("email")?,
password_digest: row.try_get("password_digest")?,
})
}
}
impl TryFrom<tokio_postgres::Row> for Point {
type Error = tokio_postgres::Error;
fn try_from(row: tokio_postgres::Row) -> Result<Self, Self::Error> {
Ok(Self(row.try_get(0)?, row.try_get(1)?, row.try_get(2)?))
}
}