Struct contack::Name[][src]

pub struct Name {
    pub given: Vec<String>,
    pub additional: Vec<String>,
    pub family: Vec<String>,
    pub prefixes: Vec<String>,
    pub suffixes: Vec<String>,
}
Expand description

A name

Stored with all the properties required for the VCard specification.

Name implements Display which allows it to be formatted in the style of: “Prefix Given Additional(s) Family Suffix.” Additional names will be separated by spaces.

Examples

Create a contact with the name “John Doe”

use contack::{Name, Contact};
 
let contact = Contact::new(Name {
   given: vec!["John".to_string()],
   family: vec!["Doe".to_string()],
   ..Default::default()
});

Fields

given: Vec<String>

The given name.

Sometimes called a first name. The “John” in “John Doe”.

additional: Vec<String>

Additional names.

Sometimes are called “middle” names. You often have more than one.

family: Vec<String>

The family name.

Sometimes called “last” names. The “Doe” in “John Doe”

prefixes: Vec<String>

Prefixes.

Often times these are things such as “Ms”, “Mr” or “Mx”, although in some cases they can be more advanced, such as “Doctor” or “Seargant”.

suffixes: Vec<String>

Suffixes

The opposite of prefixes. An example is “Esq”. Not that common in English.

Implementations

Creates a new Name

For most cases it is probably clearer to instantiate the name manually for clarity.

Example

Create a new name for “John Doe”

use contack::Name;
 
let name = Name::new(
    Some("John".to_string()),
    Some("Doe".to_string()),
    None,
    None,
    None
);

Converts the name to a single string escaped by spaces.

Each subname is separated by a space, and if they contain a space they are prefixed with a \ . This only exists to be used in the sql backend because of backwards compatability.

Example

Escape someone who has a name with spaces.

use contack::Name;
let name = vec!["Mary Rose", "Bee", "a\\"];
assert_eq!(
    Some(String::from(r#"Mary\ Rose Bee a\\"#)),
    Name::escape_with_spaces(name.into_iter())
);

Unescapes a name with spaces.

Performs the opposite of Name::escape_with_spaces

Example

Unescape someone who has a name with spaces.

use contack::Name;
let name = r#"Mary\ Rose Bee a\\"#;
assert_eq!(vec!["Mary Rose", "Bee", "a\\"], Name::unescape_with_spaces(name));
Panics

It doesn’t, just clippy thinks it does.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Allows a name to be translated into a component.

You should never need to call this directly and should prefer turning a whole contact into a VCard.

Example

Convert a name into a contact and print it out.

use contack::Name;
use contack::read_write::component::Component;
 
let name = Name {
   given: vec!["John".to_string()],
   family: vec!["Doe".to_string()],
   ..Default::default()
};

let component: Component = name.into();

// NAME:Doe;John;;;;
println!("{}", component);

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Convert self to an expression for Diesel’s query builder. Read more

Convert &self to an expression for Diesel’s query builder. Read more

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.