summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2024-04-10 18:50:43 +0300
committerLars Wirzenius <liw@liw.fi>2024-04-10 18:50:43 +0300
commitc75e69fe27c674c3edfe8e75606f65545fcdc10a (patch)
treeff959c074ad3ab50f4473d522b59a0df2360cab7
parent070a123b382a8cbc9903684d415e738cee7e5c67 (diff)
downloadhtml-page-c75e69fe27c674c3edfe8e75606f65545fcdc10a.tar.gz
feat! make callers pass in elements, not references to them
This makes using the methods a little more ergonomic and reduces the need to remember when a reference is wanted and when an element. Signed-off-by: Lars Wirzenius <liw@liw.fi> Sponsored-by: author
-rw-r--r--src/lib.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 331c09b..37747d2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -30,7 +30,7 @@ use std::fmt::{Display, Formatter};
/// ~~~
/// # use html_page::{Document, Element, Tag};
/// let title = Element::new(Tag::Title).with_text("my page");
-/// let doc = Document::default().with_head_element(&title);
+/// let doc = Document::default().with_head_element(title);
/// assert_eq!(format!("{}", doc), "<!DOCTYPE html>\n<HTML>\n\
/// <HEAD><TITLE>my page</TITLE></HEAD>\n<BODY/>\n</HTML>\n");
/// ~~~
@@ -51,23 +51,23 @@ impl Default for Document {
impl Document {
/// Append an element to the head.
- pub fn push_to_head(&mut self, e: &Element) {
+ pub fn push_to_head(&mut self, e: Element) {
self.head.push_child(e);
}
/// Append an element to the body.
- pub fn push_to_body(&mut self, e: &Element) {
+ pub fn push_to_body(&mut self, e: Element) {
self.body.push_child(e);
}
/// Append an element to the head, when constructing.
- pub fn with_head_element(mut self, e: &Element) -> Self {
+ pub fn with_head_element(mut self, e: Element) -> Self {
self.head.push_child(e);
self
}
/// Append an element to the body, when constructing.
- pub fn with_body_element(mut self, e: &Element) -> Self {
+ pub fn with_body_element(mut self, e: Element) -> Self {
self.body.push_child(e);
self
}
@@ -543,8 +543,8 @@ impl Element {
}
/// Append a child element to this element.
- pub fn push_child(&mut self, child: &Element) {
- self.children.push(Content::element(child));
+ pub fn push_child(&mut self, child: Element) {
+ self.children.push(Content::element(&child));
}
/// Remove all children.
@@ -655,7 +655,7 @@ impl Display for Content {
/// # e.push_text("hello ");
/// # let mut world = Element::new(Tag::B);
/// # world.push_text("world");
-/// # e.push_child(&world);
+/// # e.push_child(world);
/// #
/// # let mut collector = Collector::default();
/// # collector.visit(&e);
@@ -831,7 +831,7 @@ mod test {
e.push_text("hello ");
let mut world = Element::new(Tag::B);
world.push_text("world");
- e.push_child(&world);
+ e.push_child(world);
assert_eq!(e.serialize(), "<P>hello <B>world</B></P>");
}