Skip to main content

Entity

Trait Entity 

Source
pub trait Entity:
    Sized
    + Send
    + Sync
    + 'static {
    type Id: FromDatabaseValue + Into<Value> + Send + Sync + Clone;

    // Required methods
    fn table_name() -> &'static str;
    fn id(&self) -> Self::Id;

    // Provided method
    fn id_column() -> &'static str { ... }
}
Expand description

数据库实体 trait

定义实体与数据库表的映射关系

§Example

struct User {
    id: i64,
    name: String,
    email: String,
}

impl Entity for User {
    type Id = i64;

    fn table_name() -> &'static str {
        "users"
    }

    fn id(&self) -> Self::Id {
        self.id
    }
}

Required Associated Types§

Source

type Id: FromDatabaseValue + Into<Value> + Send + Sync + Clone

主键类型

Required Methods§

Source

fn table_name() -> &'static str

表名

Source

fn id(&self) -> Self::Id

获取主键值

Provided Methods§

Source

fn id_column() -> &'static str

主键列名,默认为 “id”

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§