pub trait ScaffoldingPhoneNumbers {
// Required methods
fn get_phone_number(&self, id: String) -> Option<&PhoneNumber>;
fn insert_phone_number(
&mut self,
category: String,
number: String,
country_code: String,
) -> String;
fn search_phone_numbers_by_category(
&self,
category: String,
) -> Vec<PhoneNumber>;
fn remove_phone_number(&mut self, id: String);
}Expand description
The phone number behavior of a Scaffolding object
Required Methods§
Sourcefn get_phone_number(&self, id: String) -> Option<&PhoneNumber>
fn get_phone_number(&self, id: String) -> Option<&PhoneNumber>
Retrieves a related PhoneNumber based on the specific id.
#Example
extern crate scaffolding_core;
use scaffolding_core::*;
#[scaffolding_struct("phone_numbers")]
#[derive(Clone, Debug, Deserialize, Serialize, Scaffolding, ScaffoldingPhoneNumbers)]
struct MyEntity {}
impl MyEntity {
#[scaffolding_fn("phone_numbers")]
fn new() -> Self {
Self {}
}
}
let mut entity = MyEntity::new();
let id = entity.insert_phone_number(
"home".to_string(),
"8482493561".to_string(),
"USA".to_string(),
);
assert_eq!(entity.get_phone_number(id).unwrap().number, "8482493561".to_string());Sourcefn insert_phone_number(
&mut self,
category: String,
number: String,
country_code: String,
) -> String
fn insert_phone_number( &mut self, category: String, number: String, country_code: String, ) -> String
Adds a related PhoneNumber to the Entity and returns the id for reference.
#Example
extern crate scaffolding_core;
use scaffolding_core::*;
#[scaffolding_struct("phone_numbers")]
#[derive(Clone, Debug, Deserialize, Serialize, Scaffolding, ScaffoldingPhoneNumbers)]
struct MyEntity {}
impl MyEntity {
#[scaffolding_fn("phone_numbers")]
fn new() -> Self {
Self {}
}
}
let mut entity = MyEntity::new();
let _ = entity.insert_phone_number(
"home".to_string(),
"8482493561".to_string(),
"USA".to_string(),
);
assert_eq!(entity.phone_numbers.len(), 1);Sourcefn search_phone_numbers_by_category(&self, category: String) -> Vec<PhoneNumber>
fn search_phone_numbers_by_category(&self, category: String) -> Vec<PhoneNumber>
Retrieves all the PhoneNumber with the specified category.
#Example
extern crate scaffolding_core;
use scaffolding_core::*;
#[scaffolding_struct("phone_numbers")]
#[derive(Clone, Debug, Deserialize, Serialize, Scaffolding, ScaffoldingPhoneNumbers)]
struct MyEntity {}
impl MyEntity {
#[scaffolding_fn("phone_numbers")]
fn new() -> Self {
Self {}
}
}
let mut entity = MyEntity::new();
let _ = entity.insert_phone_number(
"home".to_string(),
"8482493561".to_string(),
"USA".to_string(),
);
assert_eq!(entity.search_phone_numbers_by_category("home".to_string()).len(), 1);Sourcefn remove_phone_number(&mut self, id: String)
fn remove_phone_number(&mut self, id: String)
Removes a related PhoneNumber to the Entity.
#Example
extern crate scaffolding_core;
use scaffolding_core::*;
#[scaffolding_struct("phone_numbers")]
#[derive(Clone, Debug, Deserialize, Serialize, Scaffolding, ScaffoldingPhoneNumbers)]
struct MyEntity {}
impl MyEntity {
#[scaffolding_fn("phone_numbers")]
fn new() -> Self {
Self {}
}
}
let mut entity = MyEntity::new();
let id = entity.insert_phone_number(
"home".to_string(),
"8482493561".to_string(),
"USA".to_string(),
);
assert_eq!(entity.phone_numbers.len(), 1);
entity.remove_phone_number(id);
assert_eq!(entity.phone_numbers.len(), 0);