price_checker/src/parser.rs

31 lines
581 B
Rust

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;
pub trait PriceParser{
fn new() -> Result<Self> where Self :Sized;
fn can_parse(&self, url : &Url) -> bool;
fn parse(&self, html : &Html) -> Result<PriceResult>;
}
#[derive(Arraygen, Debug)]
#[gen_array(pub fn get_price: & dyn PriceParser)]
pub struct List {
#[in_array(get_price)]
darty: darty::Darty
}
impl List {
pub fn new() -> Result<Self> {
Ok(List {
darty: darty::Darty::new()?
})
}
}