diff --git a/source/group.rs b/source/group.rs index 144c1a8..e70439b 100644 --- a/source/group.rs +++ b/source/group.rs @@ -1,6 +1,11 @@ //! Parsing for `/~`. -use {color_eyre::Result, scraper::Html}; +use std::str::FromStr; + +use { + color_eyre::{eyre::Error, Result}, + scraper::Html, +}; use crate::{ regexes::GROUP_SUBSCRIBERS_RE, @@ -42,6 +47,15 @@ pub struct GroupWikiLink { pub url: String, } +impl FromStr for Group { + type Err = Error; + + fn from_str(s: &str) -> Result { + let html = Html::parse_document(s); + Self::from_html(&html) + } +} + impl Group { /// Parses a [`Group`] from a [`scraper::Html`] tree. pub fn from_html(html: &Html) -> Result { diff --git a/source/group_list.rs b/source/group_list.rs index 6890b61..5a126dc 100644 --- a/source/group_list.rs +++ b/source/group_list.rs @@ -1,6 +1,11 @@ //! Parsing for [`/groups`](https://tildes.net/groups). -use {color_eyre::Result, scraper::Html}; +use std::str::FromStr; + +use { + color_eyre::{eyre::Error, Result}, + scraper::Html, +}; use crate::{ regexes::{DUPLICATE_WHITESPACE_RE, GROUP_LIST_ACTIVITY_RE}, @@ -32,6 +37,15 @@ pub struct GroupListSummary { pub topic_activity: Option, } +impl FromStr for GroupList { + type Err = Error; + + fn from_str(s: &str) -> Result { + let html = Html::parse_document(s); + Self::from_html(&html) + } +} + impl GroupList { /// Parses a [`GroupList`] from a [`scraper::Html`] tree. pub fn from_html(html: &Html) -> Result {