ogc_cql2/ds/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2
3#![warn(missing_docs)]
4
5//! Groups artifacts providing Features and Resources from known types used in
6//! the geospatial ecosystem such as GeoPackage files.
7//!
8
9mod csv;
10mod gpkg;
11
12pub use csv::*;
13pub use gpkg::*;
14
15use crate::{Expression, Q};
16use async_trait::async_trait;
17use futures::stream::BoxStream;
18use std::collections::HashMap;
19
20/// A dictionary of queryable property names (strings) to [Queryables][Q] values.
21pub type Resource = HashMap<String, Q>;
22
23/// Marker trait for a type that can act as a data source provider of features
24/// and resources in the context of processing CQL2 filter expressions.
25///
26/// A CSV file, and a GeoPackage autonomous database file are examples of this.
27#[allow(dead_code)]
28pub trait DataSource {}
29
30/// Capability of a [DataSource] to provide an iterator over a collection of
31/// _Features_ and _Resources_.
32pub trait IterableDS {
33    /// Type representing a Feature which must be convertible to a [Resource].
34    type Item: TryInto<Resource, Error = Self::Err>;
35    /// Error raised by this.
36    type Err;
37
38    /// Return an iterator over this data source _Features_.
39    fn iter(&self) -> Result<impl Iterator<Item = Result<Self::Item, Self::Err>>, Self::Err>;
40}
41
42/// Capability of a [DataSource] to asynchronously stream _Features_ and [Resource]s.
43#[async_trait]
44pub trait StreamableDS {
45    /// Type representing a Feature which must be convertible to a [Resource].
46    type Item: TryInto<Resource, Error = Self::Err>;
47    /// Error raised by this.
48    type Err;
49
50    /// Return an unfiltered stream of all data source _Features_.
51    async fn fetch(&self) -> Result<BoxStream<'_, Result<Self::Item, Self::Err>>, Self::Err>;
52
53    /// Return an unfiltered stream of all data source _Resources_.
54    async fn stream(&self) -> Result<BoxStream<'_, Result<Resource, Self::Err>>, Self::Err>;
55
56    /// Return a filtered stream of _Features_ satisfying a CQL2 filter [Expression].
57    async fn fetch_where(
58        &self,
59        exp: &Expression,
60    ) -> Result<BoxStream<'_, Result<Self::Item, Self::Err>>, Self::Err>;
61
62    /// Return a filtered stream of _Resources_ satisfying a CQL2 filter [Expression].
63    async fn stream_where(
64        &self,
65        exp: &Expression,
66    ) -> Result<BoxStream<'_, Result<Resource, Self::Err>>, Self::Err>;
67}