1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::error::Result;
use crate::feature_processor::FeatureProcessor;
use async_trait::async_trait;
use std::io::{Read, Seek};
use std::path::Path;

pub trait Driver {}

pub struct OpenOpts {}

#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Extent {
    pub minx: f64,
    pub miny: f64,
    pub maxx: f64,
    pub maxy: f64,
}

pub struct SelectOpts {
    pub extent: Option<Extent>,
}

// We need a combined trait to allow storing the trait object in a struct
pub trait ReadSeek: Read + Seek {}

// Implement it for common Read + Seek inputs
impl<R: Read + Seek> ReadSeek for std::io::BufReader<R> {}
impl ReadSeek for std::fs::File {}
impl<R: AsRef<[u8]>> ReadSeek for std::io::Cursor<R> {}

pub trait Reader<'a> {
    fn open<R: 'a + ReadSeek>(reader: &'a mut R, _opts: &OpenOpts) -> Result<Self>
    where
        Self: Sized;
    fn select(&mut self, opts: &SelectOpts) -> Result<()>;
    fn process<P: FeatureProcessor>(&mut self, processor: &mut P) -> Result<()>;
}

#[async_trait]
pub trait HttpReader {
    async fn open(url: String, opts: &OpenOpts) -> Result<Self>
    where
        Self: Sized;
    async fn select(&mut self, opts: &SelectOpts) -> Result<()>;
    async fn process<P: FeatureProcessor + Send>(&mut self, processor: &mut P) -> Result<()>;
}

pub struct CreateOpts {}

pub trait Writer {
    fn open<P: AsRef<Path>>(path: P, opts: &CreateOpts) -> Result<Self>
    where
        Self: Sized;
    fn process<P: FeatureProcessor>(&mut self, processor: &mut P) -> Result<Self>
    where
        Self: Sized;
}