pub mod darty; extern crate arraygen; extern crate url; use scraper::Html; use crate::price_result::PriceResult; use arraygen::Arraygen; use url::Url; use anyhow::Result; /// Trait needed to get price from a specific website pub trait PriceParser{ /// Create a new parser fn new() -> Result where Self :Sized; /// Indicate if it can parse this URL fn can_parse(&self, url : &Url) -> bool; /// Parse the html into a price fn parse(&self, html : &Html) -> Result; } #[derive(Arraygen, Debug)] #[gen_array(pub fn get_price: & dyn PriceParser)] /// Represent the list of all the parser pub struct List { #[in_array(get_price)] darty: darty::Darty } impl List { /// Create the list pub fn new() -> Result { Ok(List { darty: darty::Darty::new()? }) } } #[test] fn test_parser_list() { let parser_list = List::new().unwrap(); assert_eq!(parser_list.get_price().len(), 1); }