ScaffoldingAddresses

Trait ScaffoldingAddresses 

Source
pub trait ScaffoldingAddresses {
    // Required methods
    fn get_address(&self, id: String) -> Option<&Address>;
    fn insert_address(
        &mut self,
        category: String,
        line_1: String,
        line_2: String,
        line_3: String,
        line_4: String,
        country_code: String,
    ) -> String;
    fn modify_address(
        &mut self,
        id: String,
        category: String,
        line_1: String,
        line_2: String,
        line_3: String,
        line_4: String,
        country_code: String,
    );
    fn search_addresses_by_category(&self, category: String) -> Vec<Address>;
    fn remove_address(&mut self, id: String);
}
Expand description

The addresses behavior of a Scaffolding object

Required Methods§

Source

fn get_address(&self, id: String) -> Option<&Address>

Retrieves a related Address to the Entity based on the specified id.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

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

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

let mut entity = MyEntity::new();
let id = entity.insert_address(
    "shipping".to_string(),
    "acmes company".to_string(),
    "14 Main Street".to_string(),
    "Big City, NY 038845".to_string(),
    "USA".to_string(),
    "USA".to_string(),
);

assert_eq!(entity.get_address(id).unwrap().category, "shipping".to_string());
Source

fn insert_address( &mut self, category: String, line_1: String, line_2: String, line_3: String, line_4: String, country_code: String, ) -> String

Insert or updates a related Address to the Entity and returns the id of the Address.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

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

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

let mut entity = MyEntity::new();
let _ = entity.insert_address(
    "shipping".to_string(),
    "acmes company".to_string(),
    "14 Main Street".to_string(),
    "Big City, NY 038845".to_string(),
    "USA".to_string(),
    "USA".to_string(),
);

assert_eq!(entity.addresses.len(), 1);
Source

fn modify_address( &mut self, id: String, category: String, line_1: String, line_2: String, line_3: String, line_4: String, country_code: String, )

Insert or updates a related Address to the Entity and returns the id of the Address for reference.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

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

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

let mut entity = MyEntity::new();
let id = entity.insert_address(
    "shipping".to_string(),
    "acmes company".to_string(),
    "14 Main Street".to_string(),
    "Big City, NY 038845".to_string(),
    "USA".to_string(),
    "USA".to_string(),
);

entity.modify_address(
    id.clone(),
    "billing".to_string(),
    "acmes company".to_string(),
    "14 Main Street".to_string(),
    "Big City, NY 038845".to_string(),
    "USA".to_string(),
    "USA".to_string(),);

assert_eq!(entity.get_address(id).unwrap().category, "billing".to_string());
Source

fn search_addresses_by_category(&self, category: String) -> Vec<Address>

Retrieves all the Addresses with the specified category.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

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

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

let mut entity = MyEntity::new();
let address = entity.insert_address(
    "shipping".to_string(),
    "acmes company".to_string(),
    "14 Main Street".to_string(),
    "Big City, NY 038845".to_string(),
    "USA".to_string(),
    "USA".to_string(),
);

assert_eq!(entity.search_addresses_by_category("shipping".to_string()).len(), 1);
Source

fn remove_address(&mut self, id: String)

Removes a related Address to the Entity.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

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

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

let mut entity = MyEntity::new();
let id = entity.insert_address(
    "shipping".to_string(),
    "acmes company".to_string(),
    "14 Main Street".to_string(),
    "Big City, NY 038845".to_string(),
    "USA".to_string(),
    "USA".to_string(),
);
assert_eq!(entity.addresses.len(), 1);

entity.remove_address(id);
assert_eq!(entity.addresses.len(), 0);

Implementors§