Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(prelude_import)]
- #[prelude_import]
- use std::prelude::rust_2021::*;
- #[macro_use]
- extern crate std;
- use geozero::ToGeo;
- use geo::{Geometry, Point};
- use regex::Regex;
- use gdal::{Dataset, vector::{OwnedFeatureIterator, Feature as GdalFeature, FieldValue}};
- use ouroboros::self_referencing;
- use std::{marker::PhantomData, error::Error, fs::File};
- use flatgeobuf::{
- FgbReader, FallibleStreamingIterator, reader_state::FeaturesSelectedSeek,
- FeatureProperties,
- };
- trait Driver {
- fn can_open(path: &str) -> bool
- where
- Self: Sized;
- fn open(path: &str) -> Result<Self, Box<dyn Error>>
- where
- Self: Sized;
- fn forward(&mut self) -> Result<bool, Box<dyn Error>>;
- fn get_field_i64(&self, field_name: &str) -> Result<Option<i64>, Box<dyn Error>>;
- fn get_field_point(&self, field_name: &str) -> Result<Option<Point>, Box<dyn Error>>;
- }
- impl Driver for Box<dyn Driver> {
- fn can_open(path: &str) -> bool
- where
- Self: Sized,
- {
- ::core::panicking::panic("explicit panic")
- }
- fn open(path: &str) -> Result<Self, Box<dyn Error>>
- where
- Self: Sized,
- {
- ::core::panicking::panic("explicit panic")
- }
- fn forward(&mut self) -> Result<bool, Box<dyn Error>> {
- self.forward()
- }
- fn get_field_i64(&self, field_name: &str) -> Result<Option<i64>, Box<dyn Error>> {
- self.as_ref().get_field_i64(field_name)
- }
- fn get_field_point(
- &self,
- field_name: &str,
- ) -> Result<Option<Point>, Box<dyn Error>> {
- self.as_ref().get_field_point(field_name)
- }
- }
- ///Encapsulates implementation details for a self-referencing struct. This module is only visible when using --document-private-items.
- mod ouroboros_impl_fgb_driver {
- use super::*;
- ///The self-referencing struct.
- pub struct FgbDriver {
- #[doc(hidden)]
- features_selected: FgbReader<'static, File, FeaturesSelectedSeek>,
- #[doc(hidden)]
- fp: ::ouroboros::macro_help::AliasableBox<File>,
- }
- fn check_if_okay_according_to_checkers(
- fp: File,
- features_selected_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> FgbReader<'this, File, FeaturesSelectedSeek>,
- ) {
- let mut fp = fp;
- let features_selected = features_selected_builder(&mut fp);
- let features_selected = features_selected;
- BorrowedFields::<'_, '_> {
- features_selected: &features_selected,
- };
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of making your code both easier to refactor and more readable. Call [`build()`](Self::build) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
- */
- pub(super) struct FgbDriverBuilder<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> FgbReader<'this, File, FeaturesSelectedSeek>,
- > {
- pub(super) fp: File,
- pub(super) features_selected_builder: FeaturesSelectedBuilder_,
- }
- impl<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> FgbReader<'this, File, FeaturesSelectedSeek>,
- > FgbDriverBuilder<FeaturesSelectedBuilder_> {
- ///Calls [`FgbDriver::new()`](FgbDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
- pub(super) fn build(self) -> FgbDriver {
- FgbDriver::new(self.fp, self.features_selected_builder)
- }
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of making your code both easier to refactor and more readable. Call [`build()`](Self::build) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
- */
- pub(super) struct FgbDriverAsyncBuilder<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = FgbReader<'this, File, FeaturesSelectedSeek>,
- > + 'this,
- >,
- >,
- > {
- pub(super) fp: File,
- pub(super) features_selected_builder: FeaturesSelectedBuilder_,
- }
- impl<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = FgbReader<'this, File, FeaturesSelectedSeek>,
- > + 'this,
- >,
- >,
- > FgbDriverAsyncBuilder<FeaturesSelectedBuilder_> {
- ///Calls [`FgbDriver::new()`](FgbDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
- pub(super) async fn build(self) -> FgbDriver {
- FgbDriver::new_async(self.fp, self.features_selected_builder).await
- }
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of making your code both easier to refactor and more readable. Call [`build()`](Self::build) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
- */
- pub(super) struct FgbDriverAsyncSendBuilder<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = FgbReader<'this, File, FeaturesSelectedSeek>,
- > + ::core::marker::Send + 'this,
- >,
- >,
- > {
- pub(super) fp: File,
- pub(super) features_selected_builder: FeaturesSelectedBuilder_,
- }
- impl<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = FgbReader<'this, File, FeaturesSelectedSeek>,
- > + ::core::marker::Send + 'this,
- >,
- >,
- > FgbDriverAsyncSendBuilder<FeaturesSelectedBuilder_> {
- ///Calls [`FgbDriver::new()`](FgbDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
- pub(super) async fn build(self) -> FgbDriver {
- FgbDriver::new_async_send(self.fp, self.features_selected_builder).await
- }
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of makin your code both easier to refactor and more readable. Call [`try_build()`](Self::try_build) or [`try_build_or_recover()`](Self::try_build_or_recover) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
- */
- pub(super) struct FgbDriverTryBuilder<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- Error_,
- > {
- pub(super) fp: File,
- pub(super) features_selected_builder: FeaturesSelectedBuilder_,
- }
- impl<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- Error_,
- > FgbDriverTryBuilder<FeaturesSelectedBuilder_, Error_> {
- ///Calls [`FgbDriver::try_new()`](FgbDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
- pub(super) fn try_build(self) -> ::core::result::Result<FgbDriver, Error_> {
- FgbDriver::try_new(self.fp, self.features_selected_builder)
- }
- ///Calls [`FgbDriver::try_new_or_recover()`](FgbDriver::try_new_or_recover) using the provided values. This is preferrable over calling `try_new_or_recover()` directly for the reasons listed above.
- pub(super) fn try_build_or_recover(
- self,
- ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
- FgbDriver::try_new_or_recover(self.fp, self.features_selected_builder)
- }
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of makin your code both easier to refactor and more readable. Call [`try_build()`](Self::try_build) or [`try_build_or_recover()`](Self::try_build_or_recover) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
- */
- pub(super) struct FgbDriverAsyncTryBuilder<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- > + 'this,
- >,
- >,
- Error_,
- > {
- pub(super) fp: File,
- pub(super) features_selected_builder: FeaturesSelectedBuilder_,
- }
- impl<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- > + 'this,
- >,
- >,
- Error_,
- > FgbDriverAsyncTryBuilder<FeaturesSelectedBuilder_, Error_> {
- ///Calls [`FgbDriver::try_new()`](FgbDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
- pub(super) async fn try_build(
- self,
- ) -> ::core::result::Result<FgbDriver, Error_> {
- FgbDriver::try_new_async(self.fp, self.features_selected_builder).await
- }
- ///Calls [`FgbDriver::try_new_or_recover()`](FgbDriver::try_new_or_recover) using the provided values. This is preferrable over calling `try_new_or_recover()` directly for the reasons listed above.
- pub(super) async fn try_build_or_recover(
- self,
- ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
- FgbDriver::try_new_or_recover_async(self.fp, self.features_selected_builder)
- .await
- }
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of makin your code both easier to refactor and more readable. Call [`try_build()`](Self::try_build) or [`try_build_or_recover()`](Self::try_build_or_recover) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
- */
- pub(super) struct FgbDriverAsyncSendTryBuilder<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- > + ::core::marker::Send + 'this,
- >,
- >,
- Error_,
- > {
- pub(super) fp: File,
- pub(super) features_selected_builder: FeaturesSelectedBuilder_,
- }
- impl<
- FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- > + ::core::marker::Send + 'this,
- >,
- >,
- Error_,
- > FgbDriverAsyncSendTryBuilder<FeaturesSelectedBuilder_, Error_> {
- ///Calls [`FgbDriver::try_new()`](FgbDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
- pub(super) async fn try_build(
- self,
- ) -> ::core::result::Result<FgbDriver, Error_> {
- FgbDriver::try_new_async_send(self.fp, self.features_selected_builder).await
- }
- ///Calls [`FgbDriver::try_new_or_recover()`](FgbDriver::try_new_or_recover) using the provided values. This is preferrable over calling `try_new_or_recover()` directly for the reasons listed above.
- pub(super) async fn try_build_or_recover(
- self,
- ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
- FgbDriver::try_new_or_recover_async_send(
- self.fp,
- self.features_selected_builder,
- )
- .await
- }
- }
- ///A struct for holding immutable references to all [tail and immutably borrowed fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) in an instance of [`FgbDriver`](FgbDriver).
- pub(super) struct BorrowedFields<'outer_borrow, 'this>
- where
- 'static: 'this,
- {
- pub(super) features_selected: &'outer_borrow FgbReader<
- 'this,
- File,
- FeaturesSelectedSeek,
- >,
- }
- ///A struct for holding mutable references to all [tail fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) in an instance of [`FgbDriver`](FgbDriver).
- pub(super) struct BorrowedMutFields<'outer_borrow, 'this>
- where
- 'static: 'this,
- {
- pub(super) features_selected: &'outer_borrow mut FgbReader<
- 'this,
- File,
- FeaturesSelectedSeek,
- >,
- }
- ///A struct which contains only the [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) of [`FgbDriver`](FgbDriver).
- pub(super) struct Heads {
- pub(super) fp: File,
- }
- impl FgbDriver {
- /**Constructs a new instance of this self-referential struct. (See also [`FgbDriverBuilder::build()`](FgbDriverBuilder::build)). Each argument is a field of the new struct. Fields that refer to other fields inside the struct are initialized using functions instead of directly passing their value. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
- */
- pub(super) fn new(
- fp: File,
- features_selected_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> FgbReader<'this, File, FeaturesSelectedSeek>,
- ) -> FgbDriver {
- let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
- let fp_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
- };
- let features_selected = features_selected_builder(
- fp_illegal_static_reference,
- );
- Self { fp, features_selected }
- }
- /**Constructs a new instance of this self-referential struct. (See also [`FgbDriverAsyncBuilder::build()`](FgbDriverAsyncBuilder::build)). Each argument is a field of the new struct. Fields that refer to other fields inside the struct are initialized using functions instead of directly passing their value. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
- */
- pub(super) async fn new_async(
- fp: File,
- features_selected_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = FgbReader<'this, File, FeaturesSelectedSeek>,
- > + 'this,
- >,
- >,
- ) -> FgbDriver {
- let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
- let fp_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
- };
- let features_selected = features_selected_builder(
- fp_illegal_static_reference,
- )
- .await;
- Self { fp, features_selected }
- }
- /**Constructs a new instance of this self-referential struct. (See also [`FgbDriverAsyncSendBuilder::build()`](FgbDriverAsyncSendBuilder::build)). Each argument is a field of the new struct. Fields that refer to other fields inside the struct are initialized using functions instead of directly passing their value. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
- */
- pub(super) async fn new_async_send(
- fp: File,
- features_selected_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = FgbReader<'this, File, FeaturesSelectedSeek>,
- > + ::core::marker::Send + 'this,
- >,
- >,
- ) -> FgbDriver {
- let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
- let fp_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
- };
- let features_selected = features_selected_builder(
- fp_illegal_static_reference,
- )
- .await;
- Self { fp, features_selected }
- }
- /**(See also [`FgbDriverTryBuilder::try_build()`](FgbDriverTryBuilder::try_build).) Like [`new`](Self::new), but builders for [self-referencing fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) can return results. If any of them fail, `Err` is returned. If all of them succeed, `Ok` is returned. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
- */
- pub(super) fn try_new<Error_>(
- fp: File,
- features_selected_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- ) -> ::core::result::Result<FgbDriver, Error_> {
- FgbDriver::try_new_or_recover(fp, features_selected_builder)
- .map_err(|(error, _heads)| error)
- }
- /**(See also [`FgbDriverTryBuilder::try_build_or_recover()`](FgbDriverTryBuilder::try_build_or_recover).) Like [`try_new`](Self::try_new), but all [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) are returned in the case of an error. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
- */
- pub(super) fn try_new_or_recover<Error_>(
- fp: File,
- features_selected_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
- let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
- let fp_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
- };
- let features_selected = match features_selected_builder(
- fp_illegal_static_reference,
- ) {
- ::core::result::Result::Ok(value) => value,
- ::core::result::Result::Err(err) => {
- return ::core::result::Result::Err((
- err,
- Heads {
- fp: ::ouroboros::macro_help::unbox(fp),
- },
- ));
- }
- };
- ::core::result::Result::Ok(Self { fp, features_selected })
- }
- /**(See also [`FgbDriverAsyncTryBuilder::try_build()`](FgbDriverAsyncTryBuilder::try_build).) Like [`new`](Self::new), but builders for [self-referencing fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) can return results. If any of them fail, `Err` is returned. If all of them succeed, `Ok` is returned. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
- */
- pub(super) async fn try_new_async<Error_>(
- fp: File,
- features_selected_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- > + 'this,
- >,
- >,
- ) -> ::core::result::Result<FgbDriver, Error_> {
- FgbDriver::try_new_or_recover_async(fp, features_selected_builder)
- .await
- .map_err(|(error, _heads)| error)
- }
- /**(See also [`FgbDriverAsyncTryBuilder::try_build_or_recover()`](FgbDriverAsyncTryBuilder::try_build_or_recover).) Like [`try_new`](Self::try_new), but all [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) are returned in the case of an error. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
- */
- pub(super) async fn try_new_or_recover_async<Error_>(
- fp: File,
- features_selected_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- > + 'this,
- >,
- >,
- ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
- let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
- let fp_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
- };
- let features_selected = match features_selected_builder(
- fp_illegal_static_reference,
- )
- .await
- {
- ::core::result::Result::Ok(value) => value,
- ::core::result::Result::Err(err) => {
- return ::core::result::Result::Err((
- err,
- Heads {
- fp: ::ouroboros::macro_help::unbox(fp),
- },
- ));
- }
- };
- ::core::result::Result::Ok(Self { fp, features_selected })
- }
- /**(See also [`FgbDriverAsyncSendTryBuilder::try_build()`](FgbDriverAsyncSendTryBuilder::try_build).) Like [`new`](Self::new), but builders for [self-referencing fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) can return results. If any of them fail, `Err` is returned. If all of them succeed, `Ok` is returned. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
- */
- pub(super) async fn try_new_async_send<Error_>(
- fp: File,
- features_selected_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- > + ::core::marker::Send + 'this,
- >,
- >,
- ) -> ::core::result::Result<FgbDriver, Error_> {
- FgbDriver::try_new_or_recover_async_send(fp, features_selected_builder)
- .await
- .map_err(|(error, _heads)| error)
- }
- /**(See also [`FgbDriverAsyncSendTryBuilder::try_build_or_recover()`](FgbDriverAsyncSendTryBuilder::try_build_or_recover).) Like [`try_new`](Self::try_new), but all [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) are returned in the case of an error. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `fp` | Directly pass in the value this field should contain |
- | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
- */
- pub(super) async fn try_new_or_recover_async_send<Error_>(
- fp: File,
- features_selected_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut File,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- FgbReader<'this, File, FeaturesSelectedSeek>,
- Error_,
- >,
- > + ::core::marker::Send + 'this,
- >,
- >,
- ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
- let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
- let fp_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
- };
- let features_selected = match features_selected_builder(
- fp_illegal_static_reference,
- )
- .await
- {
- ::core::result::Result::Ok(value) => value,
- ::core::result::Result::Err(err) => {
- return ::core::result::Result::Err((
- err,
- Heads {
- fp: ::ouroboros::macro_help::unbox(fp),
- },
- ));
- }
- };
- ::core::result::Result::Ok(Self { fp, features_selected })
- }
- ///Provides an immutable reference to `features_selected`. This method was generated because `features_selected` is a [tail field](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
- #[inline(always)]
- pub(super) fn with_features_selected<'outer_borrow, ReturnType>(
- &'outer_borrow self,
- user: impl for<'this> ::core::ops::FnOnce(
- &'outer_borrow FgbReader<'this, File, FeaturesSelectedSeek>,
- ) -> ReturnType,
- ) -> ReturnType {
- user(&self.features_selected)
- }
- ///Provides an immutable reference to `features_selected`. This method was generated because `features_selected` is a [tail field](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
- #[inline(always)]
- pub(super) fn borrow_features_selected<'this>(
- &'this self,
- ) -> &'this FgbReader<'this, File, FeaturesSelectedSeek> {
- &self.features_selected
- }
- ///Provides a mutable reference to `features_selected`. This method was generated because `features_selected` is a [tail field](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions). No `borrow_features_selected_mut` function was generated because Rust's borrow checker is currently unable to guarantee that such a method would be used safely.
- #[inline(always)]
- pub(super) fn with_features_selected_mut<'outer_borrow, ReturnType>(
- &'outer_borrow mut self,
- user: impl for<'this> ::core::ops::FnOnce(
- &'outer_borrow mut FgbReader<'this, File, FeaturesSelectedSeek>,
- ) -> ReturnType,
- ) -> ReturnType {
- user(&mut self.features_selected)
- }
- ///This method provides immutable references to all [tail and immutably borrowed fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
- #[inline(always)]
- pub(super) fn with<'outer_borrow, ReturnType>(
- &'outer_borrow self,
- user: impl for<'this> ::core::ops::FnOnce(
- BorrowedFields<'outer_borrow, 'this>,
- ) -> ReturnType,
- ) -> ReturnType {
- user(BorrowedFields {
- features_selected: &self.features_selected,
- })
- }
- ///This method provides mutable references to all [tail fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
- #[inline(always)]
- pub(super) fn with_mut<'outer_borrow, ReturnType>(
- &'outer_borrow mut self,
- user: impl for<'this> ::core::ops::FnOnce(
- BorrowedMutFields<'outer_borrow, 'this>,
- ) -> ReturnType,
- ) -> ReturnType {
- user(BorrowedMutFields {
- features_selected: &mut self.features_selected,
- })
- }
- ///This function drops all internally referencing fields and returns only the [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) of this struct.
- #[allow(clippy::drop_ref)]
- #[allow(clippy::drop_copy)]
- #[allow(clippy::drop_non_drop)]
- pub(super) fn into_heads(self) -> Heads {
- ::core::mem::drop(self.features_selected);
- let fp = self.fp;
- Heads {
- fp: ::ouroboros::macro_help::unbox(fp),
- }
- }
- }
- fn type_asserts() {}
- }
- pub use ouroboros_impl_fgb_driver::FgbDriver;
- use ouroboros_impl_fgb_driver::FgbDriverBuilder;
- use ouroboros_impl_fgb_driver::FgbDriverAsyncBuilder;
- use ouroboros_impl_fgb_driver::FgbDriverAsyncSendBuilder;
- use ouroboros_impl_fgb_driver::FgbDriverTryBuilder;
- use ouroboros_impl_fgb_driver::FgbDriverAsyncTryBuilder;
- use ouroboros_impl_fgb_driver::FgbDriverAsyncSendTryBuilder;
- impl Driver for FgbDriver {
- fn can_open(path: &str) -> bool {
- path.ends_with(".fgb")
- }
- fn open(path: &str) -> Result<Self, Box<dyn Error>> {
- let fp = File::open(path)?;
- Ok(
- FgbDriverTryBuilder {
- fp,
- features_selected_builder: |fp| FgbReader::open(fp)?.select_all(),
- }
- .try_build()?,
- )
- }
- fn forward(&mut self) -> Result<bool, Box<dyn Error>> {
- Ok(
- self
- .with_features_selected_mut(|b| {
- if let Ok(c) = b.next() { return c.is_some() } else { false }
- }),
- )
- }
- fn get_field_i64(&self, field_name: &str) -> Result<Option<i64>, Box<dyn Error>> {
- let ft = self.borrow_features_selected().cur_feature();
- Ok(Some(ft.property::<i64>(field_name)?))
- }
- fn get_field_point(
- &self,
- _field_name: &str,
- ) -> Result<Option<Point>, Box<dyn Error>> {
- let ft = self.borrow_features_selected().cur_feature();
- match ft.to_geo()? {
- Geometry::Point(p) => Ok(Some(p)),
- _ => {
- ::core::panicking::panic_fmt(
- ::core::fmt::Arguments::new_v1(&["wrong geometry type!"], &[]),
- )
- }
- }
- }
- }
- ///Encapsulates implementation details for a self-referencing struct. This module is only visible when using --document-private-items.
- mod ouroboros_impl_gpkg_driver {
- use super::*;
- ///The self-referencing struct.
- pub struct GpkgDriver {
- #[doc(hidden)]
- current_feature: Option<GdalFeature<'static>>,
- #[doc(hidden)]
- feature_iterator: ::ouroboros::macro_help::AliasableBox<OwnedFeatureIterator>,
- }
- fn check_if_okay_according_to_checkers(
- feature_iterator: OwnedFeatureIterator,
- current_feature_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> Option<GdalFeature<'this>>,
- ) {
- let mut feature_iterator = feature_iterator;
- let current_feature = current_feature_builder(&mut feature_iterator);
- let current_feature = current_feature;
- BorrowedFields::<'_, '_> {
- current_feature: ¤t_feature,
- };
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of making your code both easier to refactor and more readable. Call [`build()`](Self::build) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
- */
- pub(super) struct GpkgDriverBuilder<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> Option<GdalFeature<'this>>,
- > {
- pub(super) feature_iterator: OwnedFeatureIterator,
- pub(super) current_feature_builder: CurrentFeatureBuilder_,
- }
- impl<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> Option<GdalFeature<'this>>,
- > GpkgDriverBuilder<CurrentFeatureBuilder_> {
- ///Calls [`GpkgDriver::new()`](GpkgDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
- pub(super) fn build(self) -> GpkgDriver {
- GpkgDriver::new(self.feature_iterator, self.current_feature_builder)
- }
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of making your code both easier to refactor and more readable. Call [`build()`](Self::build) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
- */
- pub(super) struct GpkgDriverAsyncBuilder<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = Option<GdalFeature<'this>>,
- > + 'this,
- >,
- >,
- > {
- pub(super) feature_iterator: OwnedFeatureIterator,
- pub(super) current_feature_builder: CurrentFeatureBuilder_,
- }
- impl<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = Option<GdalFeature<'this>>,
- > + 'this,
- >,
- >,
- > GpkgDriverAsyncBuilder<CurrentFeatureBuilder_> {
- ///Calls [`GpkgDriver::new()`](GpkgDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
- pub(super) async fn build(self) -> GpkgDriver {
- GpkgDriver::new_async(self.feature_iterator, self.current_feature_builder)
- .await
- }
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of making your code both easier to refactor and more readable. Call [`build()`](Self::build) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
- */
- pub(super) struct GpkgDriverAsyncSendBuilder<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = Option<GdalFeature<'this>>,
- > + ::core::marker::Send + 'this,
- >,
- >,
- > {
- pub(super) feature_iterator: OwnedFeatureIterator,
- pub(super) current_feature_builder: CurrentFeatureBuilder_,
- }
- impl<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = Option<GdalFeature<'this>>,
- > + ::core::marker::Send + 'this,
- >,
- >,
- > GpkgDriverAsyncSendBuilder<CurrentFeatureBuilder_> {
- ///Calls [`GpkgDriver::new()`](GpkgDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
- pub(super) async fn build(self) -> GpkgDriver {
- GpkgDriver::new_async_send(
- self.feature_iterator,
- self.current_feature_builder,
- )
- .await
- }
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of makin your code both easier to refactor and more readable. Call [`try_build()`](Self::try_build) or [`try_build_or_recover()`](Self::try_build_or_recover) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
- */
- pub(super) struct GpkgDriverTryBuilder<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::result::Result<Option<GdalFeature<'this>>, Error_>,
- Error_,
- > {
- pub(super) feature_iterator: OwnedFeatureIterator,
- pub(super) current_feature_builder: CurrentFeatureBuilder_,
- }
- impl<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::result::Result<Option<GdalFeature<'this>>, Error_>,
- Error_,
- > GpkgDriverTryBuilder<CurrentFeatureBuilder_, Error_> {
- ///Calls [`GpkgDriver::try_new()`](GpkgDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
- pub(super) fn try_build(self) -> ::core::result::Result<GpkgDriver, Error_> {
- GpkgDriver::try_new(self.feature_iterator, self.current_feature_builder)
- }
- ///Calls [`GpkgDriver::try_new_or_recover()`](GpkgDriver::try_new_or_recover) using the provided values. This is preferrable over calling `try_new_or_recover()` directly for the reasons listed above.
- pub(super) fn try_build_or_recover(
- self,
- ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
- GpkgDriver::try_new_or_recover(
- self.feature_iterator,
- self.current_feature_builder,
- )
- }
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of makin your code both easier to refactor and more readable. Call [`try_build()`](Self::try_build) or [`try_build_or_recover()`](Self::try_build_or_recover) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
- */
- pub(super) struct GpkgDriverAsyncTryBuilder<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- Option<GdalFeature<'this>>,
- Error_,
- >,
- > + 'this,
- >,
- >,
- Error_,
- > {
- pub(super) feature_iterator: OwnedFeatureIterator,
- pub(super) current_feature_builder: CurrentFeatureBuilder_,
- }
- impl<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- Option<GdalFeature<'this>>,
- Error_,
- >,
- > + 'this,
- >,
- >,
- Error_,
- > GpkgDriverAsyncTryBuilder<CurrentFeatureBuilder_, Error_> {
- ///Calls [`GpkgDriver::try_new()`](GpkgDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
- pub(super) async fn try_build(
- self,
- ) -> ::core::result::Result<GpkgDriver, Error_> {
- GpkgDriver::try_new_async(
- self.feature_iterator,
- self.current_feature_builder,
- )
- .await
- }
- ///Calls [`GpkgDriver::try_new_or_recover()`](GpkgDriver::try_new_or_recover) using the provided values. This is preferrable over calling `try_new_or_recover()` directly for the reasons listed above.
- pub(super) async fn try_build_or_recover(
- self,
- ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
- GpkgDriver::try_new_or_recover_async(
- self.feature_iterator,
- self.current_feature_builder,
- )
- .await
- }
- }
- /**A more verbose but stable way to construct self-referencing structs. It is comparable to using `StructName { field1: value1, field2: value2 }` rather than `StructName::new(value1, value2)`. This has the dual benefit of makin your code both easier to refactor and more readable. Call [`try_build()`](Self::try_build) or [`try_build_or_recover()`](Self::try_build_or_recover) to construct the actual struct. The fields of this struct should be used as follows:
- | Field | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
- */
- pub(super) struct GpkgDriverAsyncSendTryBuilder<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- Option<GdalFeature<'this>>,
- Error_,
- >,
- > + ::core::marker::Send + 'this,
- >,
- >,
- Error_,
- > {
- pub(super) feature_iterator: OwnedFeatureIterator,
- pub(super) current_feature_builder: CurrentFeatureBuilder_,
- }
- impl<
- CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- Option<GdalFeature<'this>>,
- Error_,
- >,
- > + ::core::marker::Send + 'this,
- >,
- >,
- Error_,
- > GpkgDriverAsyncSendTryBuilder<CurrentFeatureBuilder_, Error_> {
- ///Calls [`GpkgDriver::try_new()`](GpkgDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
- pub(super) async fn try_build(
- self,
- ) -> ::core::result::Result<GpkgDriver, Error_> {
- GpkgDriver::try_new_async_send(
- self.feature_iterator,
- self.current_feature_builder,
- )
- .await
- }
- ///Calls [`GpkgDriver::try_new_or_recover()`](GpkgDriver::try_new_or_recover) using the provided values. This is preferrable over calling `try_new_or_recover()` directly for the reasons listed above.
- pub(super) async fn try_build_or_recover(
- self,
- ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
- GpkgDriver::try_new_or_recover_async_send(
- self.feature_iterator,
- self.current_feature_builder,
- )
- .await
- }
- }
- ///A struct for holding immutable references to all [tail and immutably borrowed fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) in an instance of [`GpkgDriver`](GpkgDriver).
- pub(super) struct BorrowedFields<'outer_borrow, 'this>
- where
- 'static: 'this,
- {
- pub(super) current_feature: &'outer_borrow Option<GdalFeature<'this>>,
- }
- ///A struct for holding mutable references to all [tail fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) in an instance of [`GpkgDriver`](GpkgDriver).
- pub(super) struct BorrowedMutFields<'outer_borrow, 'this>
- where
- 'static: 'this,
- {
- pub(super) current_feature: &'outer_borrow mut Option<GdalFeature<'this>>,
- }
- ///A struct which contains only the [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) of [`GpkgDriver`](GpkgDriver).
- pub(super) struct Heads {
- pub(super) feature_iterator: OwnedFeatureIterator,
- }
- impl GpkgDriver {
- /**Constructs a new instance of this self-referential struct. (See also [`GpkgDriverBuilder::build()`](GpkgDriverBuilder::build)). Each argument is a field of the new struct. Fields that refer to other fields inside the struct are initialized using functions instead of directly passing their value. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
- */
- pub(super) fn new(
- feature_iterator: OwnedFeatureIterator,
- current_feature_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> Option<GdalFeature<'this>>,
- ) -> GpkgDriver {
- let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
- feature_iterator,
- );
- let feature_iterator_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
- };
- let current_feature = current_feature_builder(
- feature_iterator_illegal_static_reference,
- );
- Self {
- feature_iterator,
- current_feature,
- }
- }
- /**Constructs a new instance of this self-referential struct. (See also [`GpkgDriverAsyncBuilder::build()`](GpkgDriverAsyncBuilder::build)). Each argument is a field of the new struct. Fields that refer to other fields inside the struct are initialized using functions instead of directly passing their value. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
- */
- pub(super) async fn new_async(
- feature_iterator: OwnedFeatureIterator,
- current_feature_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = Option<GdalFeature<'this>>,
- > + 'this,
- >,
- >,
- ) -> GpkgDriver {
- let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
- feature_iterator,
- );
- let feature_iterator_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
- };
- let current_feature = current_feature_builder(
- feature_iterator_illegal_static_reference,
- )
- .await;
- Self {
- feature_iterator,
- current_feature,
- }
- }
- /**Constructs a new instance of this self-referential struct. (See also [`GpkgDriverAsyncSendBuilder::build()`](GpkgDriverAsyncSendBuilder::build)). Each argument is a field of the new struct. Fields that refer to other fields inside the struct are initialized using functions instead of directly passing their value. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
- */
- pub(super) async fn new_async_send(
- feature_iterator: OwnedFeatureIterator,
- current_feature_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = Option<GdalFeature<'this>>,
- > + ::core::marker::Send + 'this,
- >,
- >,
- ) -> GpkgDriver {
- let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
- feature_iterator,
- );
- let feature_iterator_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
- };
- let current_feature = current_feature_builder(
- feature_iterator_illegal_static_reference,
- )
- .await;
- Self {
- feature_iterator,
- current_feature,
- }
- }
- /**(See also [`GpkgDriverTryBuilder::try_build()`](GpkgDriverTryBuilder::try_build).) Like [`new`](Self::new), but builders for [self-referencing fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) can return results. If any of them fail, `Err` is returned. If all of them succeed, `Ok` is returned. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
- */
- pub(super) fn try_new<Error_>(
- feature_iterator: OwnedFeatureIterator,
- current_feature_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::result::Result<Option<GdalFeature<'this>>, Error_>,
- ) -> ::core::result::Result<GpkgDriver, Error_> {
- GpkgDriver::try_new_or_recover(feature_iterator, current_feature_builder)
- .map_err(|(error, _heads)| error)
- }
- /**(See also [`GpkgDriverTryBuilder::try_build_or_recover()`](GpkgDriverTryBuilder::try_build_or_recover).) Like [`try_new`](Self::try_new), but all [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) are returned in the case of an error. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
- */
- pub(super) fn try_new_or_recover<Error_>(
- feature_iterator: OwnedFeatureIterator,
- current_feature_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::result::Result<Option<GdalFeature<'this>>, Error_>,
- ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
- let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
- feature_iterator,
- );
- let feature_iterator_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
- };
- let current_feature = match current_feature_builder(
- feature_iterator_illegal_static_reference,
- ) {
- ::core::result::Result::Ok(value) => value,
- ::core::result::Result::Err(err) => {
- return ::core::result::Result::Err((
- err,
- Heads {
- feature_iterator: ::ouroboros::macro_help::unbox(
- feature_iterator,
- ),
- },
- ));
- }
- };
- ::core::result::Result::Ok(Self {
- feature_iterator,
- current_feature,
- })
- }
- /**(See also [`GpkgDriverAsyncTryBuilder::try_build()`](GpkgDriverAsyncTryBuilder::try_build).) Like [`new`](Self::new), but builders for [self-referencing fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) can return results. If any of them fail, `Err` is returned. If all of them succeed, `Ok` is returned. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
- */
- pub(super) async fn try_new_async<Error_>(
- feature_iterator: OwnedFeatureIterator,
- current_feature_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- Option<GdalFeature<'this>>,
- Error_,
- >,
- > + 'this,
- >,
- >,
- ) -> ::core::result::Result<GpkgDriver, Error_> {
- GpkgDriver::try_new_or_recover_async(
- feature_iterator,
- current_feature_builder,
- )
- .await
- .map_err(|(error, _heads)| error)
- }
- /**(See also [`GpkgDriverAsyncTryBuilder::try_build_or_recover()`](GpkgDriverAsyncTryBuilder::try_build_or_recover).) Like [`try_new`](Self::try_new), but all [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) are returned in the case of an error. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
- */
- pub(super) async fn try_new_or_recover_async<Error_>(
- feature_iterator: OwnedFeatureIterator,
- current_feature_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- Option<GdalFeature<'this>>,
- Error_,
- >,
- > + 'this,
- >,
- >,
- ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
- let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
- feature_iterator,
- );
- let feature_iterator_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
- };
- let current_feature = match current_feature_builder(
- feature_iterator_illegal_static_reference,
- )
- .await
- {
- ::core::result::Result::Ok(value) => value,
- ::core::result::Result::Err(err) => {
- return ::core::result::Result::Err((
- err,
- Heads {
- feature_iterator: ::ouroboros::macro_help::unbox(
- feature_iterator,
- ),
- },
- ));
- }
- };
- ::core::result::Result::Ok(Self {
- feature_iterator,
- current_feature,
- })
- }
- /**(See also [`GpkgDriverAsyncSendTryBuilder::try_build()`](GpkgDriverAsyncSendTryBuilder::try_build).) Like [`new`](Self::new), but builders for [self-referencing fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) can return results. If any of them fail, `Err` is returned. If all of them succeed, `Ok` is returned. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
- */
- pub(super) async fn try_new_async_send<Error_>(
- feature_iterator: OwnedFeatureIterator,
- current_feature_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- Option<GdalFeature<'this>>,
- Error_,
- >,
- > + ::core::marker::Send + 'this,
- >,
- >,
- ) -> ::core::result::Result<GpkgDriver, Error_> {
- GpkgDriver::try_new_or_recover_async_send(
- feature_iterator,
- current_feature_builder,
- )
- .await
- .map_err(|(error, _heads)| error)
- }
- /**(See also [`GpkgDriverAsyncSendTryBuilder::try_build_or_recover()`](GpkgDriverAsyncSendTryBuilder::try_build_or_recover).) Like [`try_new`](Self::try_new), but all [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) are returned in the case of an error. The arguments are as follows:
- | Argument | Suggested Use |
- | --- | --- |
- | `feature_iterator` | Directly pass in the value this field should contain |
- | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
- */
- pub(super) async fn try_new_or_recover_async_send<Error_>(
- feature_iterator: OwnedFeatureIterator,
- current_feature_builder: impl for<'this> ::core::ops::FnOnce(
- &'this mut OwnedFeatureIterator,
- ) -> ::core::pin::Pin<
- ::ouroboros::macro_help::alloc::boxed::Box<
- dyn ::core::future::Future<
- Output = ::core::result::Result<
- Option<GdalFeature<'this>>,
- Error_,
- >,
- > + ::core::marker::Send + 'this,
- >,
- >,
- ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
- let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
- feature_iterator,
- );
- let feature_iterator_illegal_static_reference = unsafe {
- ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
- };
- let current_feature = match current_feature_builder(
- feature_iterator_illegal_static_reference,
- )
- .await
- {
- ::core::result::Result::Ok(value) => value,
- ::core::result::Result::Err(err) => {
- return ::core::result::Result::Err((
- err,
- Heads {
- feature_iterator: ::ouroboros::macro_help::unbox(
- feature_iterator,
- ),
- },
- ));
- }
- };
- ::core::result::Result::Ok(Self {
- feature_iterator,
- current_feature,
- })
- }
- ///Provides an immutable reference to `current_feature`. This method was generated because `current_feature` is a [tail field](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
- #[inline(always)]
- pub(super) fn with_current_feature<'outer_borrow, ReturnType>(
- &'outer_borrow self,
- user: impl for<'this> ::core::ops::FnOnce(
- &'outer_borrow Option<GdalFeature<'this>>,
- ) -> ReturnType,
- ) -> ReturnType {
- user(&self.current_feature)
- }
- ///Provides an immutable reference to `current_feature`. This method was generated because `current_feature` is a [tail field](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
- #[inline(always)]
- pub(super) fn borrow_current_feature<'this>(
- &'this self,
- ) -> &'this Option<GdalFeature<'this>> {
- &self.current_feature
- }
- ///Provides a mutable reference to `current_feature`. This method was generated because `current_feature` is a [tail field](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions). No `borrow_current_feature_mut` function was generated because Rust's borrow checker is currently unable to guarantee that such a method would be used safely.
- #[inline(always)]
- pub(super) fn with_current_feature_mut<'outer_borrow, ReturnType>(
- &'outer_borrow mut self,
- user: impl for<'this> ::core::ops::FnOnce(
- &'outer_borrow mut Option<GdalFeature<'this>>,
- ) -> ReturnType,
- ) -> ReturnType {
- user(&mut self.current_feature)
- }
- ///This method provides immutable references to all [tail and immutably borrowed fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
- #[inline(always)]
- pub(super) fn with<'outer_borrow, ReturnType>(
- &'outer_borrow self,
- user: impl for<'this> ::core::ops::FnOnce(
- BorrowedFields<'outer_borrow, 'this>,
- ) -> ReturnType,
- ) -> ReturnType {
- user(BorrowedFields {
- current_feature: &self.current_feature,
- })
- }
- ///This method provides mutable references to all [tail fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
- #[inline(always)]
- pub(super) fn with_mut<'outer_borrow, ReturnType>(
- &'outer_borrow mut self,
- user: impl for<'this> ::core::ops::FnOnce(
- BorrowedMutFields<'outer_borrow, 'this>,
- ) -> ReturnType,
- ) -> ReturnType {
- user(BorrowedMutFields {
- current_feature: &mut self.current_feature,
- })
- }
- ///This function drops all internally referencing fields and returns only the [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) of this struct.
- #[allow(clippy::drop_ref)]
- #[allow(clippy::drop_copy)]
- #[allow(clippy::drop_non_drop)]
- pub(super) fn into_heads(self) -> Heads {
- ::core::mem::drop(self.current_feature);
- let feature_iterator = self.feature_iterator;
- Heads {
- feature_iterator: ::ouroboros::macro_help::unbox(feature_iterator),
- }
- }
- }
- fn type_asserts() {}
- }
- pub use ouroboros_impl_gpkg_driver::GpkgDriver;
- use ouroboros_impl_gpkg_driver::GpkgDriverBuilder;
- use ouroboros_impl_gpkg_driver::GpkgDriverAsyncBuilder;
- use ouroboros_impl_gpkg_driver::GpkgDriverAsyncSendBuilder;
- use ouroboros_impl_gpkg_driver::GpkgDriverTryBuilder;
- use ouroboros_impl_gpkg_driver::GpkgDriverAsyncTryBuilder;
- use ouroboros_impl_gpkg_driver::GpkgDriverAsyncSendTryBuilder;
- impl<'a> Driver for GpkgDriver {
- fn can_open(path: &str) -> bool {
- let re = Regex::new(
- r"^(?P<file_path>(?:.*/)?(?P<file_name>(?:.*/)?(?P<file_own_name>.*)\.(?P<extension>gpkg)))(?::(?P<layer_name>[a-z0-9_-]+))?$",
- )
- .unwrap();
- re.is_match(&path)
- }
- fn open(path: &str) -> Result<Self, Box<dyn Error>> {
- let dataset = Dataset::open(path)?;
- let layer = dataset.into_layer(0)?;
- let feature_iterator = layer.owned_features();
- GpkgDriverTryBuilder {
- feature_iterator,
- current_feature_builder: |fi| Ok(None),
- }
- .try_build()
- }
- fn forward(&mut self) -> Result<bool, Box<dyn Error>> {
- if let Some(f) = self.with_feature_iterator().next() {
- self.borrow_current_feature().replace(f);
- Ok(true)
- } else {
- Ok(false)
- }
- }
- fn get_field_i64(&self, field_name: &str) -> Result<Option<i64>, Box<dyn Error>> {
- Ok(Some(123))
- }
- fn get_field_point(
- &self,
- _field_name: &str,
- ) -> Result<Option<Point>, Box<dyn Error>> {
- Ok(Some(Point::from((12.3, 45.6))))
- }
- }
- struct MyStruct {
- x: i64,
- geometry: Point,
- }
- #[automatically_derived]
- impl ::core::fmt::Debug for MyStruct {
- fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
- ::core::fmt::Formatter::debug_struct_field2_finish(
- f,
- "MyStruct",
- "x",
- &&self.x,
- "geometry",
- &&self.geometry,
- )
- }
- }
- struct MyStructIter(Box<dyn Driver>);
- impl<'a> MyStruct {
- fn iter_from(driver: Box<dyn Driver>) -> MyStructIter {
- MyStructIter(driver)
- }
- }
- impl MyStructIter {
- fn next_(&mut self) -> Result<Option<MyStruct>, Box<dyn Error>> {
- if !self.0.forward()? {
- return Ok(None);
- }
- Ok(
- Some(MyStruct {
- x: self.0.get_field_i64("x")?.unwrap(),
- geometry: self.0.get_field_point("geometry")?.unwrap(),
- }),
- )
- }
- }
- impl Iterator for MyStructIter {
- type Item = Result<MyStruct, Box<dyn Error>>;
- fn next(&mut self) -> Option<Self::Item> {
- self.next_().transpose()
- }
- }
- fn main() -> Result<(), Box<dyn Error>> {
- let t = Box::new(FgbDriver::open("local.fgb")?) as Box<dyn Driver>;
- for item in MyStruct::iter_from(t) {
- let item = item?;
- }
- Ok(())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement