Implement FromStr.
This commit is contained in:
		
							parent
							
								
									cd560973ed
								
							
						
					
					
						commit
						2b944b57af
					
				| 
						 | 
					@ -1,6 +1,11 @@
 | 
				
			||||||
//! Parsing for `/~<group>`.
 | 
					//! Parsing for `/~<group>`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use {color_eyre::Result, scraper::Html};
 | 
					use std::str::FromStr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use {
 | 
				
			||||||
 | 
					  color_eyre::{eyre::Error, Result},
 | 
				
			||||||
 | 
					  scraper::Html,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::{
 | 
					use crate::{
 | 
				
			||||||
  regexes::GROUP_SUBSCRIBERS_RE,
 | 
					  regexes::GROUP_SUBSCRIBERS_RE,
 | 
				
			||||||
| 
						 | 
					@ -42,6 +47,15 @@ pub struct GroupWikiLink {
 | 
				
			||||||
  pub url: String,
 | 
					  pub url: String,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl FromStr for Group {
 | 
				
			||||||
 | 
					  type Err = Error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fn from_str(s: &str) -> Result<Self, Self::Err> {
 | 
				
			||||||
 | 
					    let html = Html::parse_document(s);
 | 
				
			||||||
 | 
					    Self::from_html(&html)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Group {
 | 
					impl Group {
 | 
				
			||||||
  /// Parses a [`Group`] from a [`scraper::Html`] tree.
 | 
					  /// Parses a [`Group`] from a [`scraper::Html`] tree.
 | 
				
			||||||
  pub fn from_html(html: &Html) -> Result<Self> {
 | 
					  pub fn from_html(html: &Html) -> Result<Self> {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,11 @@
 | 
				
			||||||
//! Parsing for [`/groups`](https://tildes.net/groups).
 | 
					//! 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::{
 | 
					use crate::{
 | 
				
			||||||
  regexes::{DUPLICATE_WHITESPACE_RE, GROUP_LIST_ACTIVITY_RE},
 | 
					  regexes::{DUPLICATE_WHITESPACE_RE, GROUP_LIST_ACTIVITY_RE},
 | 
				
			||||||
| 
						 | 
					@ -32,6 +37,15 @@ pub struct GroupListSummary {
 | 
				
			||||||
  pub topic_activity: Option<i32>,
 | 
					  pub topic_activity: Option<i32>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl FromStr for GroupList {
 | 
				
			||||||
 | 
					  type Err = Error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fn from_str(s: &str) -> Result<Self, Self::Err> {
 | 
				
			||||||
 | 
					    let html = Html::parse_document(s);
 | 
				
			||||||
 | 
					    Self::from_html(&html)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl GroupList {
 | 
					impl GroupList {
 | 
				
			||||||
  /// Parses a [`GroupList`] from a [`scraper::Html`] tree.
 | 
					  /// Parses a [`GroupList`] from a [`scraper::Html`] tree.
 | 
				
			||||||
  pub fn from_html(html: &Html) -> Result<Self> {
 | 
					  pub fn from_html(html: &Html) -> Result<Self> {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in New Issue