From f8c19adb0e8eb781c567b8502bee299e3f132278 Mon Sep 17 00:00:00 2001 From: James La Novara-Gsell Date: Sun, 28 Aug 2022 21:02:08 +0000 Subject: [PATCH] feat: Add clone to HtmlDocument and Xpath --- Cargo.toml | 2 +- src/html/mod.rs | 4 +++- src/xpath/mod.rs | 9 +++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9f7c7bd..06e1c3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "skyscraper" -version = "0.3.1" +version = "0.4.0" authors = ["James La Novara-Gsell "] edition = "2018" description = "XPath for HTML web scraping" diff --git a/src/html/mod.rs b/src/html/mod.rs index f1bf003..24ad394 100644 --- a/src/html/mod.rs +++ b/src/html/mod.rs @@ -27,7 +27,7 @@ pub use crate::html::parse::parse; type TagAttributes = HashMap; /// An HTML tag and its attributes. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct HtmlTag { /// Name of the tag. pub name: String, @@ -111,6 +111,7 @@ impl HtmlTag { } /// An HTML node can be either a tag or raw text. +#[derive(Clone)] pub enum HtmlNode { /// An HTML tag. Tag(HtmlTag), @@ -199,6 +200,7 @@ impl HtmlNode { /// HTML document tree represented by an indextree arena and a root node. /// /// Documents must have a single root node to be valid. +#[derive(Clone)] pub struct HtmlDocument { arena: Arena, /// The root node of the document. diff --git a/src/xpath/mod.rs b/src/xpath/mod.rs index 2781327..52320e1 100644 --- a/src/xpath/mod.rs +++ b/src/xpath/mod.rs @@ -48,14 +48,14 @@ pub use crate::xpath::parse::parse; /// ^^^^^^^^^^^^^ ^^^^^^^^^^^ /// Predicate 1 Predicate 2 /// ``` -#[derive(Debug, PartialEq, Default)] +#[derive(Debug, PartialEq, Default, Clone)] pub struct XpathQuery { /// The list of conditions. pub predicates: Vec, } /// A single condition for an XPath search. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum XpathPredicate { /// Asserts that an attribute has a value greater than the given `value`. /// @@ -161,7 +161,7 @@ impl Default for XpathAxes { } /// A type of node to search for. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum XpathSearchNodeType { /// Search for a tag with the given name. Element(String), @@ -182,7 +182,7 @@ impl Default for XpathSearchNodeType { /// ^-------------------^---- /// Search Item 1 Search item 2 /// ``` -#[derive(Debug, PartialEq, Default)] +#[derive(Debug, PartialEq, Default, Clone)] pub struct XpathSearchItem { /// The axis to search on. pub axis: XpathAxes, @@ -218,6 +218,7 @@ pub struct XpathSearchItem { /// # Ok(()) /// # } /// ``` +#[derive(Clone)] pub struct Xpath { items: Vec, }