Changed requirements for values that implement Into<String>
This commit is contained in:
@@ -12,8 +12,11 @@ impl Render for h1 {
|
||||
}
|
||||
|
||||
impl h1 {
|
||||
pub(crate) fn new(text: String) -> Self {
|
||||
Self { text }
|
||||
pub(crate) fn new<T>(text: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
Self { text: text.into() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,15 +32,18 @@ impl Render for h2 {
|
||||
}
|
||||
|
||||
impl h2 {
|
||||
pub(crate) fn new(text: String) -> Self {
|
||||
Self { text }
|
||||
pub(crate) fn new<T>(text: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
Self { text: text.into() }
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub(crate) struct link {
|
||||
rel: &'static str,
|
||||
href: &'static str,
|
||||
rel: String,
|
||||
href: String,
|
||||
}
|
||||
|
||||
impl Render for link {
|
||||
@@ -47,15 +53,22 @@ impl Render for link {
|
||||
}
|
||||
|
||||
impl link {
|
||||
pub(crate) fn new(rel: &'static str, href: &'static str) -> Self {
|
||||
Self { rel, href }
|
||||
pub(crate) fn new<T, U>(rel: T, href: U) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
U: Into<String>,
|
||||
{
|
||||
Self {
|
||||
rel: rel.into(),
|
||||
href: href.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub(crate) struct div {
|
||||
id: &'static str,
|
||||
classes: Vec<&'static str>,
|
||||
id: String,
|
||||
classes: Vec<String>,
|
||||
content: Vec<Box<dyn Render>>,
|
||||
}
|
||||
|
||||
@@ -72,10 +85,14 @@ impl Render for div {
|
||||
}
|
||||
|
||||
impl div {
|
||||
pub(crate) fn new(id: &'static str, classes: Vec<&'static str>) -> Self {
|
||||
pub(crate) fn new<T, U>(id: T, classes: Vec<U>) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
U: Into<String> + Clone,
|
||||
{
|
||||
Self {
|
||||
id,
|
||||
classes,
|
||||
id: id.into(),
|
||||
classes: classes.iter().map(|x| x.clone().into()).collect(),
|
||||
content: vec![],
|
||||
}
|
||||
}
|
||||
@@ -87,65 +104,99 @@ impl div {
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub(crate) struct p {
|
||||
id: &'static str,
|
||||
classes: Vec<&'static str>,
|
||||
text: String
|
||||
id: String,
|
||||
classes: Vec<String>,
|
||||
text: String,
|
||||
}
|
||||
|
||||
impl Render for p {
|
||||
fn render(&self) -> String {
|
||||
let classes = self.classes.join(" ");
|
||||
format!("<p id=\"{}\" class=\"{}\">{}</p>", self.id, classes, self.text)
|
||||
format!(
|
||||
"<p id=\"{}\" class=\"{}\">{}</p>",
|
||||
self.id, classes, self.text
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl p {
|
||||
pub(crate) fn new(id: &'static str, classes: Vec<&'static str>, text: String) -> Self {
|
||||
pub(crate) fn new<T, U, V>(id: T, classes: Vec<U>, text: V) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
U: Into<String> + Clone,
|
||||
V: Into<String>,
|
||||
{
|
||||
Self {
|
||||
id,
|
||||
classes,
|
||||
text
|
||||
id: id.into(),
|
||||
classes: classes.iter().map(|x| x.clone().into()).collect(),
|
||||
text: text.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub(crate) struct img {
|
||||
id: &'static str,
|
||||
classes: Vec<&'static str>,
|
||||
src: &'static str,
|
||||
id: String,
|
||||
classes: Vec<String>,
|
||||
src: String,
|
||||
}
|
||||
|
||||
impl Render for img {
|
||||
fn render(&self) -> String {
|
||||
let classes = self.classes.join(" ");
|
||||
format!("<img id=\"{}\" class=\"{}\" src=\"{}\">", self.id, classes, self.src)
|
||||
format!(
|
||||
"<img id=\"{}\" class=\"{}\" src=\"{}\">",
|
||||
self.id, classes, self.src
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl img {
|
||||
pub(crate) fn new(id: &'static str, classes: Vec<&'static str>, src: &'static str) -> Self {
|
||||
Self { id, classes, src }
|
||||
pub(crate) fn new<T, U, V>(id: T, classes: Vec<U>, src: V) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
U: Into<String> + Clone,
|
||||
V: Into<String>,
|
||||
{
|
||||
Self {
|
||||
id: id.into(),
|
||||
classes: classes.iter().map(|x| x.clone().into()).collect(),
|
||||
src: src.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub(crate) struct a {
|
||||
id: &'static str,
|
||||
classes: Vec<&'static str>,
|
||||
href: &'static str,
|
||||
id: String,
|
||||
classes: Vec<String>,
|
||||
href: String,
|
||||
text: String,
|
||||
}
|
||||
|
||||
impl Render for a {
|
||||
fn render(&self) -> String {
|
||||
let classes = self.classes.join(" ");
|
||||
format!("<a id=\"{}\" class=\"{}\" href=\"{}\">{}</a>", self.id, classes, self.href, self.text)
|
||||
format!(
|
||||
"<a id=\"{}\" class=\"{}\" href=\"{}\">{}</a>",
|
||||
self.id, classes, self.href, self.text
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl a {
|
||||
pub(crate) fn new(id: &'static str, classes: Vec<&'static str>, href: &'static str, text: String) -> Self {
|
||||
Self { id, classes, href, text }
|
||||
pub(crate) fn new<T, U, V, W>(id: T, classes: Vec<U>, href: V, text: W) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
U: Into<String> + Clone,
|
||||
V: Into<String>,
|
||||
W: Into<String>,
|
||||
{
|
||||
Self {
|
||||
id: id.into(),
|
||||
classes: classes.iter().map(|x| x.clone().into()).collect(),
|
||||
href: href.into(),
|
||||
text: text.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user