price_checker/src/parser.rs

31 lines
581 B
Rust
Raw Normal View History

2020-05-11 19:21:57 +00:00
pub mod darty;
extern crate arraygen;
2020-05-23 14:19:04 +00:00
extern crate url;
2020-05-11 19:21:57 +00:00
use scraper::Html;
use crate::price_result::PriceResult;
use arraygen::Arraygen;
2020-05-23 14:19:04 +00:00
use url::Url;
2020-05-24 08:30:41 +00:00
use anyhow::Result;
2020-05-11 19:21:57 +00:00
2020-05-24 07:27:45 +00:00
pub trait PriceParser{
2020-05-24 08:30:41 +00:00
fn new() -> Result<Self> where Self :Sized;
2020-05-23 14:19:04 +00:00
fn can_parse(&self, url : &Url) -> bool;
2020-05-24 08:30:41 +00:00
fn parse(&self, html : &Html) -> Result<PriceResult>;
2020-05-11 19:21:57 +00:00
}
#[derive(Arraygen, Debug)]
2020-05-24 07:27:45 +00:00
#[gen_array(pub fn get_price: & dyn PriceParser)]
2020-05-11 19:21:57 +00:00
pub struct List {
2020-05-24 07:27:45 +00:00
#[in_array(get_price)]
2020-05-11 19:21:57 +00:00
darty: darty::Darty
}
impl List {
2020-05-24 08:30:41 +00:00
pub fn new() -> Result<Self> {
Ok(List {
darty: darty::Darty::new()?
})
2020-05-11 19:21:57 +00:00
}
}