Skip to content

Commit

Permalink
Merge pull request #11 from rruckley/Customer_Characteristics
Browse files Browse the repository at this point in the history
add get_characteristic()
  • Loading branch information
rruckley authored Dec 19, 2023
2 parents c39023d + cccbeaa commit 73ef089
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion examples/create_customer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ fn main() {
let org = Organization::new(String::from("ACustomer"));
let customer = Customer::new(org);

dbg!(customer);
dbg!(&customer);

println!("Customer Code: {}",customer.get_characteristic("code").unwrap().value);
}
11 changes: 11 additions & 0 deletions src/tmf629/customer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ impl Customer {
self.characteristic.as_mut().unwrap().push(hash);
}

/// Try to find characteristic with given name
pub fn get_characteristic(&self, characteristic : &str) -> Option<Characteristic> {
match self.characteristic.clone() {
Some(c) => {
c.into_iter().filter(|x| x.name == characteristic).next()
},
None => None,
}

}

/// Set the name of the customer
pub fn name(&mut self, name : String) {
self.name = name.clone();
Expand Down

0 comments on commit 73ef089

Please sign in to comment.