Add in some missing types, conversions and utility methods.

This commit is contained in:
Bodil Stokke 2019-03-16 20:58:51 +00:00
parent ece0b39a60
commit e2f6fd0c08
4 changed files with 27 additions and 0 deletions

View File

@ -69,6 +69,12 @@ impl From<Id> for Class {
} }
} }
impl<'a> From<&'a str> for Class {
fn from(str: &'a str) -> Self {
Class::from_str(str).unwrap()
}
}
impl Display for Class { impl Display for Class {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
Display::fmt(&self.0, f) Display::fmt(&self.0, f)

View File

@ -58,6 +58,12 @@ impl FromStr for Id {
} }
} }
impl<'a> From<&'a str> for Id {
fn from(str: &'a str) -> Self {
Id::from_str(str).unwrap()
}
}
impl From<Class> for Id { impl From<Class> for Id {
fn from(c: Class) -> Self { fn from(c: Class) -> Self {
Id(c.to_string()) Id(c.to_string())

View File

@ -104,6 +104,16 @@ pub enum FormMethod {
Get, Get,
} }
#[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, AsStaticStr)]
pub enum FormDialogMethod {
#[strum(to_string = "post")]
Post,
#[strum(to_string = "get")]
Get,
#[strum(to_string = "dialog")]
Dialog,
}
#[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, AsStaticStr)] #[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, AsStaticStr)]
pub enum HTTPEquiv { pub enum HTTPEquiv {
#[strum(to_string = "content-security-policy")] #[strum(to_string = "content-security-policy")]

View File

@ -33,6 +33,11 @@ impl<A: Ord> SpacedSet<A> {
pub fn new() -> Self { pub fn new() -> Self {
SpacedSet(BTreeSet::new()) SpacedSet(BTreeSet::new())
} }
/// Add a value to the `SpacedSet`.
pub fn add<T: Into<A>>(&mut self, value: T) -> bool {
self.0.insert(value.into())
}
} }
impl<A: Ord> Default for SpacedSet<A> { impl<A: Ord> Default for SpacedSet<A> {