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
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);
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
Auto Trait Implementations
impl RefUnwindSafe for Name
impl UnwindSafe for Name
Blanket Implementations
Mutably borrows from an owned value. Read more
Convert self
to an expression for Diesel’s query builder. Read more
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel’s query builder. Read more