Scaffolding

Trait Scaffolding 

Source
pub trait Scaffolding {
    // Required methods
    fn log_activity(&mut self, name: String, descr: String);
    fn get_activity(&self, name: String) -> Vec<ActivityItem>;

    // Provided methods
    fn deserialized(serialized: &[u8]) -> Result<Self, DeserializeError>
       where Self: DeserializeOwned { ... }
    fn serialize(&mut self) -> String
       where Self: Serialize { ... }
}
Expand description

The core behavior of a Scaffolding object

Required Methods§

Source

fn log_activity(&mut self, name: String, descr: String)

This function adds a ActivityItem to the activity log

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

#[scaffolding_struct]
#[derive(Clone, Debug, Scaffolding)]
struct MyEntity {}

impl MyEntity {
    #[scaffolding_fn]
    fn new() -> Self {
        Self {}
    }
}

let mut entity = MyEntity::new();

entity.log_activity("cancelled".to_string(), "The customer has cancelled their service".to_string());
assert_eq!(entity.activity.len(), 1);
Source

fn get_activity(&self, name: String) -> Vec<ActivityItem>

This function retrieves all the ActivityItems that have the specified action (name)

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

#[scaffolding_struct]
#[derive(Clone, Debug, Scaffolding)]
struct MyEntity {}

impl MyEntity {
    #[scaffolding_fn]
    fn new() -> Self {
        Self {}
    }
}

let mut entity = MyEntity::new();

entity.log_activity("ordered".to_string(), "The customer has place the order".to_string());
entity.log_activity("cancelled".to_string(), "The customer has cancelled their service".to_string());
assert_eq!(entity.get_activity("cancelled".to_string()).len(), 1);

Provided Methods§

Source

fn deserialized(serialized: &[u8]) -> Result<Self, DeserializeError>
where Self: DeserializeOwned,

This function instantiates an entity from a JSON string.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

#[scaffolding_struct]
#[derive(Clone, Debug, Deserialize, Scaffolding)]
struct MyEntity {}

impl MyEntity {
    #[scaffolding_fn]
    fn new() -> Self {
        Self {}
    }
}

let json = r#"{
    "id":"b4d6c6db-7468-400a-8536-a5e83b1f2bdc",
    "created_dtm":1711802687,
    "modified_dtm":1711802687,
    "inactive_dtm":1719578687,
    "expired_dtm":1806410687,
    "activity":[
        {
            "created_dtm":1711802687,
            "action":"updated",
            "description":"The object has been updated"
        },
        {
            "created_dtm":1711802687,
            "action":"updated",
            "description":"The object has been updated"
        },
        {
            "created_dtm":1711802687,
            "action":"cancelled",
            "description":"The object has been cancelled"
        }
        ]
    }"#;
let deserialized = MyEntity::deserialized(json.as_bytes()).unwrap();

assert_eq!(deserialized.id, "b4d6c6db-7468-400a-8536-a5e83b1f2bdc");
assert_eq!(deserialized.activity.len(), 3);  
Source

fn serialize(&mut self) -> String
where Self: Serialize,

This function converts the entity to a serialize JSON string.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

#[scaffolding_struct]
#[derive(Clone, Debug, Serialize, Scaffolding)]
struct MyEntity {}

impl MyEntity {
    #[scaffolding_fn]
    fn new() -> Self {
        Self {}
    }
}

let mut entity = MyEntity::new();
let json_string = entity.serialize();

println!("{}", json_string);

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§