pub struct Person { /* private fields */ }Expand description
Represents a person with a name and contact information.
Implementations§
Source§impl Person
impl Person
Sourcepub fn update_email(&mut self, email: EmailAddress)
pub fn update_email(&mut self, email: EmailAddress)
Add or edit the email address of the person.
§Arguments
email- The new email address of the person.
§Examples
use planter_core::person::Person;
use email_address::EmailAddress;
use std::str::FromStr;
let mut person = Person::new("Margherita", "Hack").unwrap();
let email = EmailAddress::from_str("margherita.hack@example.com").unwrap();
person.update_email(email.clone());
assert_eq!(person.email(), &Some(email));Sourcepub fn rm_email(&mut self)
pub fn rm_email(&mut self)
Remove the email address of the person.
§Examples
use planter_core::person::Person;
use email_address::EmailAddress;
use std::str::FromStr;
let mut person = Person::new("Margherita", "Hack").unwrap();
let email = EmailAddress::from_str("margherita.hack@example.com").unwrap();
person.update_email(email.clone());
assert_eq!(person.email(), &Some(email));
person.rm_email();
assert!(person.email().is_none());Sourcepub fn update_phone(&mut self, phone: PhoneNumber)
pub fn update_phone(&mut self, phone: PhoneNumber)
Add or edit the phone number of the person.
§Arguments
phone- The new phone number of the person.
§Examples
use planter_core::person::Person;
use std::str::FromStr;
use phonenumber::PhoneNumber;
let mut person = Person::new("Margherita", "Hack").unwrap();
let phone = PhoneNumber::from_str("+1234567890").unwrap();
person.update_phone(phone.clone());
assert_eq!(person.phone(), &Some(phone));Sourcepub fn rm_phone(&mut self)
pub fn rm_phone(&mut self)
Remove the phone number of the person.
§Examples
use planter_core::person::Person;
use std::str::FromStr;
use phonenumber::PhoneNumber;
let mut person = Person::new("Margherita", "Hack").unwrap();
let phone = PhoneNumber::from_str("+1234567890").unwrap();
person.update_phone(phone.clone());
assert_eq!(person.phone(), &Some(phone));
person.rm_phone();
assert!(person.phone().is_none());Sourcepub fn phone(&self) -> &Option<PhoneNumber>
pub fn phone(&self) -> &Option<PhoneNumber>
Get the phone number of the person.
§Examples
use planter_core::person::Person;
use phonenumber::PhoneNumber;
use std::str::FromStr;
let mut person = Person::new("Margherita", "Hack").unwrap();
let phone = PhoneNumber::from_str("+1234567890").unwrap();
person.update_phone(phone.clone());
assert_eq!(person.phone(), &Some(phone));Sourcepub fn email(&self) -> &Option<EmailAddress>
pub fn email(&self) -> &Option<EmailAddress>
Get the email of the person.
§Examples
use planter_core::person::Person;
use email_address::EmailAddress;
use std::str::FromStr;
let mut person = Person::new("Margherita", "Hack").unwrap();
let email = EmailAddress::from_str("margherita.hack@example.com").unwrap();
person.update_email(email.clone());
assert_eq!(person.email(), &Some(email));Sourcepub fn full_name(&self) -> String
pub fn full_name(&self) -> String
Get the name of the person.
§Examples
use planter_core::person::Person;
let mut person = Person::new("Margherita", "Hack").unwrap();
assert_eq!(person.full_name(), "Margherita Hack");Sourcepub fn first_name(&self) -> &str
pub fn first_name(&self) -> &str
Get the first name of the person.
§Examples
use planter_core::person::Person;
let person = Person::new("Margherita", "Hack").unwrap();
assert_eq!(person.first_name(), "Margherita");Sourcepub fn update_first_name(&mut self, name: impl Into<String>) -> Result<()>
pub fn update_first_name(&mut self, name: impl Into<String>) -> Result<()>
Update the first name of the person.
§Errors
It can return an error, if the input name can’t be converted to
NameString
§Examples
use planter_core::person::Person;
let mut person = Person::new("Margaret", "Hack").unwrap();
person.update_first_name("Margherita").unwrap();
assert_eq!(person.first_name(), "Margherita");Sourcepub fn last_name(&self) -> &str
pub fn last_name(&self) -> &str
Get the last name of the person.
§Examples
use planter_core::person::Person;
let mut person = Person::new("Margherita", "Hack").unwrap();
assert_eq!(person.last_name(), "Hack");Sourcepub fn update_last_name(&mut self, name: impl Into<String>) -> Result<()>
pub fn update_last_name(&mut self, name: impl Into<String>) -> Result<()>
Update the last name of the person.
§Errors
It can return an error, if the input name can’t be converted to
NameString
§Examples
use planter_core::person::Person;
let mut person = Person::new("Margherita", "Hacker").unwrap();
person.update_last_name("Hack").unwrap();
assert_eq!(person.last_name(), "Hack");Trait Implementations§
impl Eq for Person
impl StructuralPartialEq for Person
Auto Trait Implementations§
impl Freeze for Person
impl RefUnwindSafe for Person
impl Send for Person
impl Sync for Person
impl Unpin for Person
impl UnwindSafe for Person
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more