Person

Struct Person 

Source
pub struct Person { /* private fields */ }
Expand description

Represents a person with a name and contact information.

Implementations§

Source§

impl Person

Source

pub fn new(name: impl Into<String>, surname: impl Into<String>) -> Option<Self>

Create a new Person with the given name.

§Arguments
  • name - The name of the person.
§Returns

A new Person instance.

§Examples
use planter_core::person::Person;

let person = Person::new("Margherita", "Hack").unwrap();
Source

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));
Source

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());
Source

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));
Source

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());
Source

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));
Source

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));
Source

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");
Source

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");
Source

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");
Source

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");
Source

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§

Source§

impl Clone for Person

Source§

fn clone(&self) -> Person

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Person

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Person

Source§

fn eq(&self, other: &Person) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Person

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.