Skip to main content

BusinessObject

Trait BusinessObject 

Source
pub trait BusinessObject: Sized {
    // Required methods
    fn entity_info() -> EntityInfo;
    fn to_object(&self) -> Object;
    fn from_object(object: &Object) -> Self;
}
Expand description

A record as a Rust struct. Derive it:

use ravenrs_app::{BusinessEnum, BusinessObject};

#[derive(BusinessEnum, Clone, Debug, PartialEq)]
enum Kind {
    #[option(caption = "Corrente")]
    Checking,
    #[option(caption = "Poupança")]
    Savings,
}

#[derive(BusinessObject, Clone, Debug, PartialEq)]
#[object(caption = "Contas", navigation = "Cadastros", icon = "wallet")]
struct Account {
    #[field(key)]
    id: i64,
    #[field(caption = "Nome", default_property)]
    name: String,
    #[field(caption = "Tipo")]
    kind: Kind,
    #[field(caption = "Saldo inicial", money)]
    opening: i64,
}

let entity = Account::entity_info();
assert_eq!(entity.caption, "Contas");
assert!(entity.check().is_ok());
let account = Account { id: 1, name: "Carteira".into(), kind: Kind::Savings, opening: 1250 };
assert_eq!(Account::from_object(&account.to_object()), account);

Required Methods§

Source

fn entity_info() -> EntityInfo

What the record is.

Source

fn to_object(&self) -> Object

As a dynamic record.

Source

fn from_object(object: &Object) -> Self

From a dynamic record.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§