[][src]Trait bookbinder_ast::ContributorSource

pub trait ContributorSource<'a>: Sized {
    fn to_vec(self) -> Vec<Cow<'a, str>>;

    fn is_single_name(&self) -> bool { ... }
fn to_single(self) -> Option<Cow<'a, str>> { ... } }

Implemented for str-like types which can be interpreted as either a single name or multiple names; this is a convenience trait to allow overloading methods to add names rather than having to have a method to add a single name and one to add multiple names. It shouldn't really be a worry for end users, since it is pre-implemented for likely types.

let single_name = "Name One";
let multiple_names = vec!["Name One, Name Two"];

assert!(single_name.is_single_name());
assert_eq!(multiple_names.is_single_name(), false);
assert_eq!(single_name.to_vec(), vec!["Name One"]);
assert_eq!(multiple_names.clone().to_vec(), multiple_names.clone());
assert_eq!(single_name.to_single(), Some(Cow::Borrowed("Name One")));
assert_eq!(multiple_names.to_single(), None);

Required methods

fn to_vec(self) -> Vec<Cow<'a, str>>

get a vec of names, even if the source was a single name

Loading content...

Provided methods

fn is_single_name(&self) -> bool

does this represent only a single name?

fn to_single(self) -> Option<Cow<'a, str>>

get a single name if this represented only a single name

Loading content...

Implementations on Foreign Types

impl<'a> ContributorSource<'a> for String[src]

impl<'a> ContributorSource<'a> for Vec<String>[src]

impl<'a, '_> ContributorSource<'a> for &'_ [String][src]

impl<'a> ContributorSource<'a> for &'a str[src]

impl<'a> ContributorSource<'a> for Vec<&'a str>[src]

impl<'a, '_> ContributorSource<'a> for &'_ [&'a str][src]

impl<'a> ContributorSource<'a> for Cow<'a, str>[src]

impl<'a> ContributorSource<'a> for Vec<Cow<'a, str>>[src]

impl<'a, '_> ContributorSource<'a> for &'_ [Cow<'a, str>][src]

impl<'a> ContributorSource<'a> for Vec<CowStr<'a>>[src]

Loading content...

Implementors

impl<'a> ContributorSource<'a> for CowStr<'a>[src]

Loading content...