Advertisement
Guest User

Untitled

a guest
Jan 7th, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 75.00 KB | None | 0 0
  1. #![feature(prelude_import)]
  2. #[prelude_import]
  3. use std::prelude::rust_2021::*;
  4. #[macro_use]
  5. extern crate std;
  6. use geozero::ToGeo;
  7. use geo::{Geometry, Point};
  8. use regex::Regex;
  9. use gdal::{Dataset, vector::{OwnedFeatureIterator, Feature as GdalFeature, FieldValue}};
  10. use ouroboros::self_referencing;
  11. use std::{marker::PhantomData, error::Error, fs::File};
  12. use flatgeobuf::{
  13.     FgbReader, FallibleStreamingIterator, reader_state::FeaturesSelectedSeek,
  14.     FeatureProperties,
  15. };
  16. trait Driver {
  17.     fn can_open(path: &str) -> bool
  18.     where
  19.         Self: Sized;
  20.     fn open(path: &str) -> Result<Self, Box<dyn Error>>
  21.     where
  22.         Self: Sized;
  23.     fn forward(&mut self) -> Result<bool, Box<dyn Error>>;
  24.     fn get_field_i64(&self, field_name: &str) -> Result<Option<i64>, Box<dyn Error>>;
  25.     fn get_field_point(&self, field_name: &str) -> Result<Option<Point>, Box<dyn Error>>;
  26. }
  27. impl Driver for Box<dyn Driver> {
  28.     fn can_open(path: &str) -> bool
  29.     where
  30.         Self: Sized,
  31.     {
  32.         ::core::panicking::panic("explicit panic")
  33.     }
  34.     fn open(path: &str) -> Result<Self, Box<dyn Error>>
  35.     where
  36.         Self: Sized,
  37.     {
  38.         ::core::panicking::panic("explicit panic")
  39.     }
  40.     fn forward(&mut self) -> Result<bool, Box<dyn Error>> {
  41.         self.forward()
  42.     }
  43.     fn get_field_i64(&self, field_name: &str) -> Result<Option<i64>, Box<dyn Error>> {
  44.         self.as_ref().get_field_i64(field_name)
  45.     }
  46.     fn get_field_point(
  47.         &self,
  48.         field_name: &str,
  49.     ) -> Result<Option<Point>, Box<dyn Error>> {
  50.         self.as_ref().get_field_point(field_name)
  51.     }
  52. }
  53. ///Encapsulates implementation details for a self-referencing struct. This module is only visible when using --document-private-items.
  54. mod ouroboros_impl_fgb_driver {
  55.     use super::*;
  56.     ///The self-referencing struct.
  57.     pub struct FgbDriver {
  58.         #[doc(hidden)]
  59.         features_selected: FgbReader<'static, File, FeaturesSelectedSeek>,
  60.        #[doc(hidden)]
  61.        fp: ::ouroboros::macro_help::AliasableBox<File>,
  62.    }
  63.    fn check_if_okay_according_to_checkers(
  64.        fp: File,
  65.        features_selected_builder: impl for<'this> ::core::ops::FnOnce(
  66.             &'this mut File,
  67.        ) -> FgbReader<'this, File, FeaturesSelectedSeek>,
  68.     ) {
  69.         let mut fp = fp;
  70.         let features_selected = features_selected_builder(&mut fp);
  71.         let features_selected = features_selected;
  72.         BorrowedFields::<'_, '_> {
  73.             features_selected: &features_selected,
  74.         };
  75.     }
  76.     /**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:
  77.  
  78. | Field | Suggested Use |
  79. | --- | --- |
  80. | `fp` | Directly pass in the value this field should contain |
  81. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
  82. */
  83.     pub(super) struct FgbDriverBuilder<
  84.         FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  85.                &'this mut File,
  86.             ) -> FgbReader<'this, File, FeaturesSelectedSeek>,
  87.    > {
  88.        pub(super) fp: File,
  89.        pub(super) features_selected_builder: FeaturesSelectedBuilder_,
  90.    }
  91.    impl<
  92.        FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  93.                 &'this mut File,
  94.            ) -> FgbReader<'this, File, FeaturesSelectedSeek>,
  95.     > FgbDriverBuilder<FeaturesSelectedBuilder_> {
  96.         ///Calls [`FgbDriver::new()`](FgbDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
  97.         pub(super) fn build(self) -> FgbDriver {
  98.             FgbDriver::new(self.fp, self.features_selected_builder)
  99.         }
  100.     }
  101.     /**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:
  102.  
  103. | Field | Suggested Use |
  104. | --- | --- |
  105. | `fp` | Directly pass in the value this field should contain |
  106. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
  107. */
  108.     pub(super) struct FgbDriverAsyncBuilder<
  109.         FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  110.                &'this mut File,
  111.             ) -> ::core::pin::Pin<
  112.                     ::ouroboros::macro_help::alloc::boxed::Box<
  113.                         dyn ::core::future::Future<
  114.                             Output = FgbReader<'this, File, FeaturesSelectedSeek>,
  115.                        > + 'this,
  116.                     >,
  117.                 >,
  118.     > {
  119.         pub(super) fp: File,
  120.         pub(super) features_selected_builder: FeaturesSelectedBuilder_,
  121.     }
  122.     impl<
  123.         FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  124.                &'this mut File,
  125.             ) -> ::core::pin::Pin<
  126.                     ::ouroboros::macro_help::alloc::boxed::Box<
  127.                         dyn ::core::future::Future<
  128.                             Output = FgbReader<'this, File, FeaturesSelectedSeek>,
  129.                        > + 'this,
  130.                     >,
  131.                 >,
  132.     > FgbDriverAsyncBuilder<FeaturesSelectedBuilder_> {
  133.         ///Calls [`FgbDriver::new()`](FgbDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
  134.         pub(super) async fn build(self) -> FgbDriver {
  135.             FgbDriver::new_async(self.fp, self.features_selected_builder).await
  136.         }
  137.     }
  138.     /**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:
  139.  
  140. | Field | Suggested Use |
  141. | --- | --- |
  142. | `fp` | Directly pass in the value this field should contain |
  143. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
  144. */
  145.     pub(super) struct FgbDriverAsyncSendBuilder<
  146.         FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  147.                &'this mut File,
  148.             ) -> ::core::pin::Pin<
  149.                     ::ouroboros::macro_help::alloc::boxed::Box<
  150.                         dyn ::core::future::Future<
  151.                             Output = FgbReader<'this, File, FeaturesSelectedSeek>,
  152.                        > + ::core::marker::Send + 'this,
  153.                     >,
  154.                 >,
  155.     > {
  156.         pub(super) fp: File,
  157.         pub(super) features_selected_builder: FeaturesSelectedBuilder_,
  158.     }
  159.     impl<
  160.         FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  161.                &'this mut File,
  162.             ) -> ::core::pin::Pin<
  163.                     ::ouroboros::macro_help::alloc::boxed::Box<
  164.                         dyn ::core::future::Future<
  165.                             Output = FgbReader<'this, File, FeaturesSelectedSeek>,
  166.                        > + ::core::marker::Send + 'this,
  167.                     >,
  168.                 >,
  169.     > FgbDriverAsyncSendBuilder<FeaturesSelectedBuilder_> {
  170.         ///Calls [`FgbDriver::new()`](FgbDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
  171.         pub(super) async fn build(self) -> FgbDriver {
  172.             FgbDriver::new_async_send(self.fp, self.features_selected_builder).await
  173.         }
  174.     }
  175.     /**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:
  176.  
  177. | Field | Suggested Use |
  178. | --- | --- |
  179. | `fp` | Directly pass in the value this field should contain |
  180. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
  181. */
  182.     pub(super) struct FgbDriverTryBuilder<
  183.         FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  184.                &'this mut File,
  185.             ) -> ::core::result::Result<
  186.                     FgbReader<'this, File, FeaturesSelectedSeek>,
  187.                    Error_,
  188.                >,
  189.        Error_,
  190.    > {
  191.        pub(super) fp: File,
  192.        pub(super) features_selected_builder: FeaturesSelectedBuilder_,
  193.    }
  194.    impl<
  195.        FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  196.                 &'this mut File,
  197.            ) -> ::core::result::Result<
  198.                    FgbReader<'this, File, FeaturesSelectedSeek>,
  199.                     Error_,
  200.                 >,
  201.         Error_,
  202.     > FgbDriverTryBuilder<FeaturesSelectedBuilder_, Error_> {
  203.         ///Calls [`FgbDriver::try_new()`](FgbDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
  204.         pub(super) fn try_build(self) -> ::core::result::Result<FgbDriver, Error_> {
  205.             FgbDriver::try_new(self.fp, self.features_selected_builder)
  206.         }
  207.         ///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.
  208.         pub(super) fn try_build_or_recover(
  209.             self,
  210.         ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
  211.             FgbDriver::try_new_or_recover(self.fp, self.features_selected_builder)
  212.         }
  213.     }
  214.     /**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:
  215.  
  216. | Field | Suggested Use |
  217. | --- | --- |
  218. | `fp` | Directly pass in the value this field should contain |
  219. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
  220. */
  221.     pub(super) struct FgbDriverAsyncTryBuilder<
  222.         FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  223.                &'this mut File,
  224.             ) -> ::core::pin::Pin<
  225.                     ::ouroboros::macro_help::alloc::boxed::Box<
  226.                         dyn ::core::future::Future<
  227.                             Output = ::core::result::Result<
  228.                                 FgbReader<'this, File, FeaturesSelectedSeek>,
  229.                                Error_,
  230.                            >,
  231.                        > + 'this,
  232.                     >,
  233.                 >,
  234.         Error_,
  235.     > {
  236.         pub(super) fp: File,
  237.         pub(super) features_selected_builder: FeaturesSelectedBuilder_,
  238.     }
  239.     impl<
  240.         FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  241.                &'this mut File,
  242.             ) -> ::core::pin::Pin<
  243.                     ::ouroboros::macro_help::alloc::boxed::Box<
  244.                         dyn ::core::future::Future<
  245.                             Output = ::core::result::Result<
  246.                                 FgbReader<'this, File, FeaturesSelectedSeek>,
  247.                                Error_,
  248.                            >,
  249.                        > + 'this,
  250.                     >,
  251.                 >,
  252.         Error_,
  253.     > FgbDriverAsyncTryBuilder<FeaturesSelectedBuilder_, Error_> {
  254.         ///Calls [`FgbDriver::try_new()`](FgbDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
  255.         pub(super) async fn try_build(
  256.             self,
  257.         ) -> ::core::result::Result<FgbDriver, Error_> {
  258.             FgbDriver::try_new_async(self.fp, self.features_selected_builder).await
  259.         }
  260.         ///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.
  261.         pub(super) async fn try_build_or_recover(
  262.             self,
  263.         ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
  264.             FgbDriver::try_new_or_recover_async(self.fp, self.features_selected_builder)
  265.                 .await
  266.         }
  267.     }
  268.     /**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:
  269.  
  270. | Field | Suggested Use |
  271. | --- | --- |
  272. | `fp` | Directly pass in the value this field should contain |
  273. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
  274. */
  275.     pub(super) struct FgbDriverAsyncSendTryBuilder<
  276.         FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  277.                &'this mut File,
  278.             ) -> ::core::pin::Pin<
  279.                     ::ouroboros::macro_help::alloc::boxed::Box<
  280.                         dyn ::core::future::Future<
  281.                             Output = ::core::result::Result<
  282.                                 FgbReader<'this, File, FeaturesSelectedSeek>,
  283.                                Error_,
  284.                            >,
  285.                        > + ::core::marker::Send + 'this,
  286.                     >,
  287.                 >,
  288.         Error_,
  289.     > {
  290.         pub(super) fp: File,
  291.         pub(super) features_selected_builder: FeaturesSelectedBuilder_,
  292.     }
  293.     impl<
  294.         FeaturesSelectedBuilder_: for<'this> ::core::ops::FnOnce(
  295.                &'this mut File,
  296.             ) -> ::core::pin::Pin<
  297.                     ::ouroboros::macro_help::alloc::boxed::Box<
  298.                         dyn ::core::future::Future<
  299.                             Output = ::core::result::Result<
  300.                                 FgbReader<'this, File, FeaturesSelectedSeek>,
  301.                                Error_,
  302.                            >,
  303.                        > + ::core::marker::Send + 'this,
  304.                     >,
  305.                 >,
  306.         Error_,
  307.     > FgbDriverAsyncSendTryBuilder<FeaturesSelectedBuilder_, Error_> {
  308.         ///Calls [`FgbDriver::try_new()`](FgbDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
  309.         pub(super) async fn try_build(
  310.             self,
  311.         ) -> ::core::result::Result<FgbDriver, Error_> {
  312.             FgbDriver::try_new_async_send(self.fp, self.features_selected_builder).await
  313.         }
  314.         ///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.
  315.         pub(super) async fn try_build_or_recover(
  316.             self,
  317.         ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
  318.             FgbDriver::try_new_or_recover_async_send(
  319.                     self.fp,
  320.                     self.features_selected_builder,
  321.                 )
  322.                 .await
  323.         }
  324.     }
  325.     ///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).
  326.     pub(super) struct BorrowedFields<'outer_borrow, 'this>
  327.     where
  328.         'static: 'this,
  329.     {
  330.         pub(super) features_selected: &'outer_borrow FgbReader<
  331.            'this,
  332.             File,
  333.             FeaturesSelectedSeek,
  334.         >,
  335.     }
  336.     ///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).
  337.     pub(super) struct BorrowedMutFields<'outer_borrow, 'this>
  338.     where
  339.         'static: 'this,
  340.     {
  341.         pub(super) features_selected: &'outer_borrow mut FgbReader<
  342.            'this,
  343.             File,
  344.             FeaturesSelectedSeek,
  345.         >,
  346.     }
  347.     ///A struct which contains only the [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) of [`FgbDriver`](FgbDriver).
  348.     pub(super) struct Heads {
  349.         pub(super) fp: File,
  350.     }
  351.     impl FgbDriver {
  352.         /**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:
  353.  
  354. | Argument | Suggested Use |
  355. | --- | --- |
  356. | `fp` | Directly pass in the value this field should contain |
  357. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
  358. */
  359.         pub(super) fn new(
  360.             fp: File,
  361.             features_selected_builder: impl for<'this> ::core::ops::FnOnce(
  362.                &'this mut File,
  363.             ) -> FgbReader<'this, File, FeaturesSelectedSeek>,
  364.        ) -> FgbDriver {
  365.            let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
  366.            let fp_illegal_static_reference = unsafe {
  367.                ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
  368.            };
  369.            let features_selected = features_selected_builder(
  370.                fp_illegal_static_reference,
  371.            );
  372.            Self { fp, features_selected }
  373.        }
  374.        /**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:
  375.  
  376. | Argument | Suggested Use |
  377. | --- | --- |
  378. | `fp` | Directly pass in the value this field should contain |
  379. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
  380. */
  381.        pub(super) async fn new_async(
  382.            fp: File,
  383.            features_selected_builder: impl for<'this> ::core::ops::FnOnce(
  384.                 &'this mut File,
  385.            ) -> ::core::pin::Pin<
  386.                    ::ouroboros::macro_help::alloc::boxed::Box<
  387.                        dyn ::core::future::Future<
  388.                            Output = FgbReader<'this, File, FeaturesSelectedSeek>,
  389.                         > + 'this,
  390.                    >,
  391.                >,
  392.        ) -> FgbDriver {
  393.            let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
  394.            let fp_illegal_static_reference = unsafe {
  395.                ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
  396.            };
  397.            let features_selected = features_selected_builder(
  398.                    fp_illegal_static_reference,
  399.                )
  400.                .await;
  401.            Self { fp, features_selected }
  402.        }
  403.        /**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:
  404.  
  405. | Argument | Suggested Use |
  406. | --- | --- |
  407. | `fp` | Directly pass in the value this field should contain |
  408. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> features_selected: _` |
  409. */
  410.        pub(super) async fn new_async_send(
  411.            fp: File,
  412.            features_selected_builder: impl for<'this> ::core::ops::FnOnce(
  413.                 &'this mut File,
  414.            ) -> ::core::pin::Pin<
  415.                    ::ouroboros::macro_help::alloc::boxed::Box<
  416.                        dyn ::core::future::Future<
  417.                            Output = FgbReader<'this, File, FeaturesSelectedSeek>,
  418.                         > + ::core::marker::Send + 'this,
  419.                    >,
  420.                >,
  421.        ) -> FgbDriver {
  422.            let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
  423.            let fp_illegal_static_reference = unsafe {
  424.                ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
  425.            };
  426.            let features_selected = features_selected_builder(
  427.                    fp_illegal_static_reference,
  428.                )
  429.                .await;
  430.            Self { fp, features_selected }
  431.        }
  432.        /**(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:
  433.  
  434. | Argument | Suggested Use |
  435. | --- | --- |
  436. | `fp` | Directly pass in the value this field should contain |
  437. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
  438. */
  439.        pub(super) fn try_new<Error_>(
  440.            fp: File,
  441.            features_selected_builder: impl for<'this> ::core::ops::FnOnce(
  442.                 &'this mut File,
  443.            ) -> ::core::result::Result<
  444.                    FgbReader<'this, File, FeaturesSelectedSeek>,
  445.                     Error_,
  446.                 >,
  447.         ) -> ::core::result::Result<FgbDriver, Error_> {
  448.             FgbDriver::try_new_or_recover(fp, features_selected_builder)
  449.                 .map_err(|(error, _heads)| error)
  450.         }
  451.         /**(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:
  452.  
  453. | Argument | Suggested Use |
  454. | --- | --- |
  455. | `fp` | Directly pass in the value this field should contain |
  456. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
  457. */
  458.         pub(super) fn try_new_or_recover<Error_>(
  459.             fp: File,
  460.             features_selected_builder: impl for<'this> ::core::ops::FnOnce(
  461.                &'this mut File,
  462.             ) -> ::core::result::Result<
  463.                     FgbReader<'this, File, FeaturesSelectedSeek>,
  464.                    Error_,
  465.                >,
  466.        ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
  467.            let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
  468.            let fp_illegal_static_reference = unsafe {
  469.                ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
  470.            };
  471.            let features_selected = match features_selected_builder(
  472.                fp_illegal_static_reference,
  473.            ) {
  474.                ::core::result::Result::Ok(value) => value,
  475.                ::core::result::Result::Err(err) => {
  476.                    return ::core::result::Result::Err((
  477.                        err,
  478.                        Heads {
  479.                            fp: ::ouroboros::macro_help::unbox(fp),
  480.                        },
  481.                    ));
  482.                }
  483.            };
  484.            ::core::result::Result::Ok(Self { fp, features_selected })
  485.        }
  486.        /**(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:
  487.  
  488. | Argument | Suggested Use |
  489. | --- | --- |
  490. | `fp` | Directly pass in the value this field should contain |
  491. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
  492. */
  493.        pub(super) async fn try_new_async<Error_>(
  494.            fp: File,
  495.            features_selected_builder: impl for<'this> ::core::ops::FnOnce(
  496.                 &'this mut File,
  497.            ) -> ::core::pin::Pin<
  498.                    ::ouroboros::macro_help::alloc::boxed::Box<
  499.                        dyn ::core::future::Future<
  500.                            Output = ::core::result::Result<
  501.                                FgbReader<'this, File, FeaturesSelectedSeek>,
  502.                                 Error_,
  503.                             >,
  504.                         > + 'this,
  505.                    >,
  506.                >,
  507.        ) -> ::core::result::Result<FgbDriver, Error_> {
  508.            FgbDriver::try_new_or_recover_async(fp, features_selected_builder)
  509.                .await
  510.                .map_err(|(error, _heads)| error)
  511.        }
  512.        /**(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:
  513.  
  514. | Argument | Suggested Use |
  515. | --- | --- |
  516. | `fp` | Directly pass in the value this field should contain |
  517. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
  518. */
  519.        pub(super) async fn try_new_or_recover_async<Error_>(
  520.            fp: File,
  521.            features_selected_builder: impl for<'this> ::core::ops::FnOnce(
  522.                 &'this mut File,
  523.            ) -> ::core::pin::Pin<
  524.                    ::ouroboros::macro_help::alloc::boxed::Box<
  525.                        dyn ::core::future::Future<
  526.                            Output = ::core::result::Result<
  527.                                FgbReader<'this, File, FeaturesSelectedSeek>,
  528.                                 Error_,
  529.                             >,
  530.                         > + 'this,
  531.                    >,
  532.                >,
  533.        ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
  534.            let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
  535.            let fp_illegal_static_reference = unsafe {
  536.                ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
  537.            };
  538.            let features_selected = match features_selected_builder(
  539.                    fp_illegal_static_reference,
  540.                )
  541.                .await
  542.            {
  543.                ::core::result::Result::Ok(value) => value,
  544.                ::core::result::Result::Err(err) => {
  545.                    return ::core::result::Result::Err((
  546.                        err,
  547.                        Heads {
  548.                            fp: ::ouroboros::macro_help::unbox(fp),
  549.                        },
  550.                    ));
  551.                }
  552.            };
  553.            ::core::result::Result::Ok(Self { fp, features_selected })
  554.        }
  555.        /**(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:
  556.  
  557. | Argument | Suggested Use |
  558. | --- | --- |
  559. | `fp` | Directly pass in the value this field should contain |
  560. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
  561. */
  562.        pub(super) async fn try_new_async_send<Error_>(
  563.            fp: File,
  564.            features_selected_builder: impl for<'this> ::core::ops::FnOnce(
  565.                 &'this mut File,
  566.            ) -> ::core::pin::Pin<
  567.                    ::ouroboros::macro_help::alloc::boxed::Box<
  568.                        dyn ::core::future::Future<
  569.                            Output = ::core::result::Result<
  570.                                FgbReader<'this, File, FeaturesSelectedSeek>,
  571.                                 Error_,
  572.                             >,
  573.                         > + ::core::marker::Send + 'this,
  574.                    >,
  575.                >,
  576.        ) -> ::core::result::Result<FgbDriver, Error_> {
  577.            FgbDriver::try_new_or_recover_async_send(fp, features_selected_builder)
  578.                .await
  579.                .map_err(|(error, _heads)| error)
  580.        }
  581.        /**(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:
  582.  
  583. | Argument | Suggested Use |
  584. | --- | --- |
  585. | `fp` | Directly pass in the value this field should contain |
  586. | `features_selected_builder` | Use a function or closure: `(fp: &mut _) -> Result<features_selected: _, Error_>` |
  587. */
  588.        pub(super) async fn try_new_or_recover_async_send<Error_>(
  589.            fp: File,
  590.            features_selected_builder: impl for<'this> ::core::ops::FnOnce(
  591.                 &'this mut File,
  592.            ) -> ::core::pin::Pin<
  593.                    ::ouroboros::macro_help::alloc::boxed::Box<
  594.                        dyn ::core::future::Future<
  595.                            Output = ::core::result::Result<
  596.                                FgbReader<'this, File, FeaturesSelectedSeek>,
  597.                                 Error_,
  598.                             >,
  599.                         > + ::core::marker::Send + 'this,
  600.                    >,
  601.                >,
  602.        ) -> ::core::result::Result<FgbDriver, (Error_, Heads)> {
  603.            let mut fp = ::ouroboros::macro_help::aliasable_boxed(fp);
  604.            let fp_illegal_static_reference = unsafe {
  605.                ::ouroboros::macro_help::change_lifetime_mut(&mut *fp)
  606.            };
  607.            let features_selected = match features_selected_builder(
  608.                    fp_illegal_static_reference,
  609.                )
  610.                .await
  611.            {
  612.                ::core::result::Result::Ok(value) => value,
  613.                ::core::result::Result::Err(err) => {
  614.                    return ::core::result::Result::Err((
  615.                        err,
  616.                        Heads {
  617.                            fp: ::ouroboros::macro_help::unbox(fp),
  618.                        },
  619.                    ));
  620.                }
  621.            };
  622.            ::core::result::Result::Ok(Self { fp, features_selected })
  623.        }
  624.        ///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).
  625.        #[inline(always)]
  626.        pub(super) fn with_features_selected<'outer_borrow, ReturnType>(
  627.             &'outer_borrow self,
  628.            user: impl for<'this> ::core::ops::FnOnce(
  629.                 &'outer_borrow FgbReader<'this, File, FeaturesSelectedSeek>,
  630.             ) -> ReturnType,
  631.         ) -> ReturnType {
  632.             user(&self.features_selected)
  633.         }
  634.         ///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).
  635.         #[inline(always)]
  636.         pub(super) fn borrow_features_selected<'this>(
  637.            &'this self,
  638.         ) -> &'this FgbReader<'this, File, FeaturesSelectedSeek> {
  639.             &self.features_selected
  640.         }
  641.         ///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.
  642.         #[inline(always)]
  643.         pub(super) fn with_features_selected_mut<'outer_borrow, ReturnType>(
  644.            &'outer_borrow mut self,
  645.             user: impl for<'this> ::core::ops::FnOnce(
  646.                &'outer_borrow mut FgbReader<'this, File, FeaturesSelectedSeek>,
  647.            ) -> ReturnType,
  648.        ) -> ReturnType {
  649.            user(&mut self.features_selected)
  650.        }
  651.        ///This method provides immutable references to all [tail and immutably borrowed fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
  652.        #[inline(always)]
  653.        pub(super) fn with<'outer_borrow, ReturnType>(
  654.             &'outer_borrow self,
  655.            user: impl for<'this> ::core::ops::FnOnce(
  656.                 BorrowedFields<'outer_borrow, 'this>,
  657.             ) -> ReturnType,
  658.         ) -> ReturnType {
  659.             user(BorrowedFields {
  660.                 features_selected: &self.features_selected,
  661.             })
  662.         }
  663.         ///This method provides mutable references to all [tail fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
  664.         #[inline(always)]
  665.         pub(super) fn with_mut<'outer_borrow, ReturnType>(
  666.            &'outer_borrow mut self,
  667.             user: impl for<'this> ::core::ops::FnOnce(
  668.                BorrowedMutFields<'outer_borrow, 'this>,
  669.            ) -> ReturnType,
  670.        ) -> ReturnType {
  671.            user(BorrowedMutFields {
  672.                features_selected: &mut self.features_selected,
  673.            })
  674.        }
  675.        ///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.
  676.        #[allow(clippy::drop_ref)]
  677.        #[allow(clippy::drop_copy)]
  678.        #[allow(clippy::drop_non_drop)]
  679.        pub(super) fn into_heads(self) -> Heads {
  680.            ::core::mem::drop(self.features_selected);
  681.            let fp = self.fp;
  682.            Heads {
  683.                fp: ::ouroboros::macro_help::unbox(fp),
  684.            }
  685.        }
  686.    }
  687.    fn type_asserts() {}
  688. }
  689. pub use ouroboros_impl_fgb_driver::FgbDriver;
  690. use ouroboros_impl_fgb_driver::FgbDriverBuilder;
  691. use ouroboros_impl_fgb_driver::FgbDriverAsyncBuilder;
  692. use ouroboros_impl_fgb_driver::FgbDriverAsyncSendBuilder;
  693. use ouroboros_impl_fgb_driver::FgbDriverTryBuilder;
  694. use ouroboros_impl_fgb_driver::FgbDriverAsyncTryBuilder;
  695. use ouroboros_impl_fgb_driver::FgbDriverAsyncSendTryBuilder;
  696. impl Driver for FgbDriver {
  697.    fn can_open(path: &str) -> bool {
  698.        path.ends_with(".fgb")
  699.    }
  700.    fn open(path: &str) -> Result<Self, Box<dyn Error>> {
  701.        let fp = File::open(path)?;
  702.        Ok(
  703.            FgbDriverTryBuilder {
  704.                fp,
  705.                features_selected_builder: |fp| FgbReader::open(fp)?.select_all(),
  706.            }
  707.                .try_build()?,
  708.        )
  709.    }
  710.    fn forward(&mut self) -> Result<bool, Box<dyn Error>> {
  711.        Ok(
  712.            self
  713.                .with_features_selected_mut(|b| {
  714.                    if let Ok(c) = b.next() { return c.is_some() } else { false }
  715.                }),
  716.        )
  717.    }
  718.    fn get_field_i64(&self, field_name: &str) -> Result<Option<i64>, Box<dyn Error>> {
  719.        let ft = self.borrow_features_selected().cur_feature();
  720.        Ok(Some(ft.property::<i64>(field_name)?))
  721.    }
  722.    fn get_field_point(
  723.        &self,
  724.        _field_name: &str,
  725.    ) -> Result<Option<Point>, Box<dyn Error>> {
  726.        let ft = self.borrow_features_selected().cur_feature();
  727.        match ft.to_geo()? {
  728.            Geometry::Point(p) => Ok(Some(p)),
  729.            _ => {
  730.                ::core::panicking::panic_fmt(
  731.                    ::core::fmt::Arguments::new_v1(&["wrong geometry type!"], &[]),
  732.                )
  733.            }
  734.        }
  735.    }
  736. }
  737. ///Encapsulates implementation details for a self-referencing struct. This module is only visible when using --document-private-items.
  738. mod ouroboros_impl_gpkg_driver {
  739.    use super::*;
  740.    ///The self-referencing struct.
  741.    pub struct GpkgDriver {
  742.        #[doc(hidden)]
  743.        current_feature: Option<GdalFeature<'static>>,
  744.         #[doc(hidden)]
  745.         feature_iterator: ::ouroboros::macro_help::AliasableBox<OwnedFeatureIterator>,
  746.     }
  747.     fn check_if_okay_according_to_checkers(
  748.         feature_iterator: OwnedFeatureIterator,
  749.         current_feature_builder: impl for<'this> ::core::ops::FnOnce(
  750.            &'this mut OwnedFeatureIterator,
  751.         ) -> Option<GdalFeature<'this>>,
  752.    ) {
  753.        let mut feature_iterator = feature_iterator;
  754.        let current_feature = current_feature_builder(&mut feature_iterator);
  755.        let current_feature = current_feature;
  756.        BorrowedFields::<'_, '_> {
  757.            current_feature: &current_feature,
  758.        };
  759.    }
  760.    /**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:
  761.  
  762. | Field | Suggested Use |
  763. | --- | --- |
  764. | `feature_iterator` | Directly pass in the value this field should contain |
  765. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
  766. */
  767.    pub(super) struct GpkgDriverBuilder<
  768.        CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  769.                 &'this mut OwnedFeatureIterator,
  770.            ) -> Option<GdalFeature<'this>>,
  771.     > {
  772.         pub(super) feature_iterator: OwnedFeatureIterator,
  773.         pub(super) current_feature_builder: CurrentFeatureBuilder_,
  774.     }
  775.     impl<
  776.         CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  777.                &'this mut OwnedFeatureIterator,
  778.             ) -> Option<GdalFeature<'this>>,
  779.    > GpkgDriverBuilder<CurrentFeatureBuilder_> {
  780.        ///Calls [`GpkgDriver::new()`](GpkgDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
  781.        pub(super) fn build(self) -> GpkgDriver {
  782.            GpkgDriver::new(self.feature_iterator, self.current_feature_builder)
  783.        }
  784.    }
  785.    /**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:
  786.  
  787. | Field | Suggested Use |
  788. | --- | --- |
  789. | `feature_iterator` | Directly pass in the value this field should contain |
  790. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
  791. */
  792.    pub(super) struct GpkgDriverAsyncBuilder<
  793.        CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  794.                 &'this mut OwnedFeatureIterator,
  795.            ) -> ::core::pin::Pin<
  796.                    ::ouroboros::macro_help::alloc::boxed::Box<
  797.                        dyn ::core::future::Future<
  798.                            Output = Option<GdalFeature<'this>>,
  799.                         > + 'this,
  800.                    >,
  801.                >,
  802.    > {
  803.        pub(super) feature_iterator: OwnedFeatureIterator,
  804.        pub(super) current_feature_builder: CurrentFeatureBuilder_,
  805.    }
  806.    impl<
  807.        CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  808.                 &'this mut OwnedFeatureIterator,
  809.            ) -> ::core::pin::Pin<
  810.                    ::ouroboros::macro_help::alloc::boxed::Box<
  811.                        dyn ::core::future::Future<
  812.                            Output = Option<GdalFeature<'this>>,
  813.                         > + 'this,
  814.                    >,
  815.                >,
  816.    > GpkgDriverAsyncBuilder<CurrentFeatureBuilder_> {
  817.        ///Calls [`GpkgDriver::new()`](GpkgDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
  818.        pub(super) async fn build(self) -> GpkgDriver {
  819.            GpkgDriver::new_async(self.feature_iterator, self.current_feature_builder)
  820.                .await
  821.        }
  822.    }
  823.    /**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:
  824.  
  825. | Field | Suggested Use |
  826. | --- | --- |
  827. | `feature_iterator` | Directly pass in the value this field should contain |
  828. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
  829. */
  830.    pub(super) struct GpkgDriverAsyncSendBuilder<
  831.        CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  832.                 &'this mut OwnedFeatureIterator,
  833.            ) -> ::core::pin::Pin<
  834.                    ::ouroboros::macro_help::alloc::boxed::Box<
  835.                        dyn ::core::future::Future<
  836.                            Output = Option<GdalFeature<'this>>,
  837.                         > + ::core::marker::Send + 'this,
  838.                    >,
  839.                >,
  840.    > {
  841.        pub(super) feature_iterator: OwnedFeatureIterator,
  842.        pub(super) current_feature_builder: CurrentFeatureBuilder_,
  843.    }
  844.    impl<
  845.        CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  846.                 &'this mut OwnedFeatureIterator,
  847.            ) -> ::core::pin::Pin<
  848.                    ::ouroboros::macro_help::alloc::boxed::Box<
  849.                        dyn ::core::future::Future<
  850.                            Output = Option<GdalFeature<'this>>,
  851.                         > + ::core::marker::Send + 'this,
  852.                    >,
  853.                >,
  854.    > GpkgDriverAsyncSendBuilder<CurrentFeatureBuilder_> {
  855.        ///Calls [`GpkgDriver::new()`](GpkgDriver::new) using the provided values. This is preferrable over calling `new()` directly for the reasons listed above.
  856.        pub(super) async fn build(self) -> GpkgDriver {
  857.            GpkgDriver::new_async_send(
  858.                    self.feature_iterator,
  859.                    self.current_feature_builder,
  860.                )
  861.                .await
  862.        }
  863.    }
  864.    /**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:
  865.  
  866. | Field | Suggested Use |
  867. | --- | --- |
  868. | `feature_iterator` | Directly pass in the value this field should contain |
  869. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
  870. */
  871.    pub(super) struct GpkgDriverTryBuilder<
  872.        CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  873.                 &'this mut OwnedFeatureIterator,
  874.            ) -> ::core::result::Result<Option<GdalFeature<'this>>, Error_>,
  875.         Error_,
  876.     > {
  877.         pub(super) feature_iterator: OwnedFeatureIterator,
  878.         pub(super) current_feature_builder: CurrentFeatureBuilder_,
  879.     }
  880.     impl<
  881.         CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  882.                &'this mut OwnedFeatureIterator,
  883.             ) -> ::core::result::Result<Option<GdalFeature<'this>>, Error_>,
  884.        Error_,
  885.    > GpkgDriverTryBuilder<CurrentFeatureBuilder_, Error_> {
  886.        ///Calls [`GpkgDriver::try_new()`](GpkgDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
  887.        pub(super) fn try_build(self) -> ::core::result::Result<GpkgDriver, Error_> {
  888.            GpkgDriver::try_new(self.feature_iterator, self.current_feature_builder)
  889.        }
  890.        ///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.
  891.        pub(super) fn try_build_or_recover(
  892.            self,
  893.        ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
  894.            GpkgDriver::try_new_or_recover(
  895.                self.feature_iterator,
  896.                self.current_feature_builder,
  897.            )
  898.        }
  899.    }
  900.    /**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:
  901.  
  902. | Field | Suggested Use |
  903. | --- | --- |
  904. | `feature_iterator` | Directly pass in the value this field should contain |
  905. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
  906. */
  907.    pub(super) struct GpkgDriverAsyncTryBuilder<
  908.        CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  909.                 &'this mut OwnedFeatureIterator,
  910.            ) -> ::core::pin::Pin<
  911.                    ::ouroboros::macro_help::alloc::boxed::Box<
  912.                        dyn ::core::future::Future<
  913.                            Output = ::core::result::Result<
  914.                                Option<GdalFeature<'this>>,
  915.                                 Error_,
  916.                             >,
  917.                         > + 'this,
  918.                    >,
  919.                >,
  920.        Error_,
  921.    > {
  922.        pub(super) feature_iterator: OwnedFeatureIterator,
  923.        pub(super) current_feature_builder: CurrentFeatureBuilder_,
  924.    }
  925.    impl<
  926.        CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  927.                 &'this mut OwnedFeatureIterator,
  928.            ) -> ::core::pin::Pin<
  929.                    ::ouroboros::macro_help::alloc::boxed::Box<
  930.                        dyn ::core::future::Future<
  931.                            Output = ::core::result::Result<
  932.                                Option<GdalFeature<'this>>,
  933.                                 Error_,
  934.                             >,
  935.                         > + 'this,
  936.                    >,
  937.                >,
  938.        Error_,
  939.    > GpkgDriverAsyncTryBuilder<CurrentFeatureBuilder_, Error_> {
  940.        ///Calls [`GpkgDriver::try_new()`](GpkgDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
  941.        pub(super) async fn try_build(
  942.            self,
  943.        ) -> ::core::result::Result<GpkgDriver, Error_> {
  944.            GpkgDriver::try_new_async(
  945.                    self.feature_iterator,
  946.                    self.current_feature_builder,
  947.                )
  948.                .await
  949.        }
  950.        ///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.
  951.        pub(super) async fn try_build_or_recover(
  952.            self,
  953.        ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
  954.            GpkgDriver::try_new_or_recover_async(
  955.                    self.feature_iterator,
  956.                    self.current_feature_builder,
  957.                )
  958.                .await
  959.        }
  960.    }
  961.    /**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:
  962.  
  963. | Field | Suggested Use |
  964. | --- | --- |
  965. | `feature_iterator` | Directly pass in the value this field should contain |
  966. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
  967. */
  968.    pub(super) struct GpkgDriverAsyncSendTryBuilder<
  969.        CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  970.                 &'this mut OwnedFeatureIterator,
  971.            ) -> ::core::pin::Pin<
  972.                    ::ouroboros::macro_help::alloc::boxed::Box<
  973.                        dyn ::core::future::Future<
  974.                            Output = ::core::result::Result<
  975.                                Option<GdalFeature<'this>>,
  976.                                 Error_,
  977.                             >,
  978.                         > + ::core::marker::Send + 'this,
  979.                    >,
  980.                >,
  981.        Error_,
  982.    > {
  983.        pub(super) feature_iterator: OwnedFeatureIterator,
  984.        pub(super) current_feature_builder: CurrentFeatureBuilder_,
  985.    }
  986.    impl<
  987.        CurrentFeatureBuilder_: for<'this> ::core::ops::FnOnce(
  988.                 &'this mut OwnedFeatureIterator,
  989.            ) -> ::core::pin::Pin<
  990.                    ::ouroboros::macro_help::alloc::boxed::Box<
  991.                        dyn ::core::future::Future<
  992.                            Output = ::core::result::Result<
  993.                                Option<GdalFeature<'this>>,
  994.                                 Error_,
  995.                             >,
  996.                         > + ::core::marker::Send + 'this,
  997.                    >,
  998.                >,
  999.        Error_,
  1000.    > GpkgDriverAsyncSendTryBuilder<CurrentFeatureBuilder_, Error_> {
  1001.        ///Calls [`GpkgDriver::try_new()`](GpkgDriver::try_new) using the provided values. This is preferrable over calling `try_new()` directly for the reasons listed above.
  1002.        pub(super) async fn try_build(
  1003.            self,
  1004.        ) -> ::core::result::Result<GpkgDriver, Error_> {
  1005.            GpkgDriver::try_new_async_send(
  1006.                    self.feature_iterator,
  1007.                    self.current_feature_builder,
  1008.                )
  1009.                .await
  1010.        }
  1011.        ///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.
  1012.        pub(super) async fn try_build_or_recover(
  1013.            self,
  1014.        ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
  1015.            GpkgDriver::try_new_or_recover_async_send(
  1016.                    self.feature_iterator,
  1017.                    self.current_feature_builder,
  1018.                )
  1019.                .await
  1020.        }
  1021.    }
  1022.    ///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).
  1023.    pub(super) struct BorrowedFields<'outer_borrow, 'this>
  1024.    where
  1025.        'static: 'this,
  1026.    {
  1027.        pub(super) current_feature: &'outer_borrow Option<GdalFeature<'this>>,
  1028.    }
  1029.    ///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).
  1030.    pub(super) struct BorrowedMutFields<'outer_borrow, 'this>
  1031.    where
  1032.        'static: 'this,
  1033.    {
  1034.        pub(super) current_feature: &'outer_borrow mut Option<GdalFeature<'this>>,
  1035.    }
  1036.    ///A struct which contains only the [head fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions) of [`GpkgDriver`](GpkgDriver).
  1037.    pub(super) struct Heads {
  1038.        pub(super) feature_iterator: OwnedFeatureIterator,
  1039.    }
  1040.    impl GpkgDriver {
  1041.        /**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:
  1042.  
  1043. | Argument | Suggested Use |
  1044. | --- | --- |
  1045. | `feature_iterator` | Directly pass in the value this field should contain |
  1046. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
  1047. */
  1048.        pub(super) fn new(
  1049.            feature_iterator: OwnedFeatureIterator,
  1050.            current_feature_builder: impl for<'this> ::core::ops::FnOnce(
  1051.                 &'this mut OwnedFeatureIterator,
  1052.            ) -> Option<GdalFeature<'this>>,
  1053.         ) -> GpkgDriver {
  1054.             let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
  1055.                 feature_iterator,
  1056.             );
  1057.             let feature_iterator_illegal_static_reference = unsafe {
  1058.                 ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
  1059.             };
  1060.             let current_feature = current_feature_builder(
  1061.                 feature_iterator_illegal_static_reference,
  1062.             );
  1063.             Self {
  1064.                 feature_iterator,
  1065.                 current_feature,
  1066.             }
  1067.         }
  1068.         /**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:
  1069.  
  1070. | Argument | Suggested Use |
  1071. | --- | --- |
  1072. | `feature_iterator` | Directly pass in the value this field should contain |
  1073. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
  1074. */
  1075.         pub(super) async fn new_async(
  1076.             feature_iterator: OwnedFeatureIterator,
  1077.             current_feature_builder: impl for<'this> ::core::ops::FnOnce(
  1078.                &'this mut OwnedFeatureIterator,
  1079.             ) -> ::core::pin::Pin<
  1080.                     ::ouroboros::macro_help::alloc::boxed::Box<
  1081.                         dyn ::core::future::Future<
  1082.                             Output = Option<GdalFeature<'this>>,
  1083.                        > + 'this,
  1084.                     >,
  1085.                 >,
  1086.         ) -> GpkgDriver {
  1087.             let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
  1088.                 feature_iterator,
  1089.             );
  1090.             let feature_iterator_illegal_static_reference = unsafe {
  1091.                 ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
  1092.             };
  1093.             let current_feature = current_feature_builder(
  1094.                     feature_iterator_illegal_static_reference,
  1095.                 )
  1096.                 .await;
  1097.             Self {
  1098.                 feature_iterator,
  1099.                 current_feature,
  1100.             }
  1101.         }
  1102.         /**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:
  1103.  
  1104. | Argument | Suggested Use |
  1105. | --- | --- |
  1106. | `feature_iterator` | Directly pass in the value this field should contain |
  1107. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> current_feature: _` |
  1108. */
  1109.         pub(super) async fn new_async_send(
  1110.             feature_iterator: OwnedFeatureIterator,
  1111.             current_feature_builder: impl for<'this> ::core::ops::FnOnce(
  1112.                &'this mut OwnedFeatureIterator,
  1113.             ) -> ::core::pin::Pin<
  1114.                     ::ouroboros::macro_help::alloc::boxed::Box<
  1115.                         dyn ::core::future::Future<
  1116.                             Output = Option<GdalFeature<'this>>,
  1117.                        > + ::core::marker::Send + 'this,
  1118.                     >,
  1119.                 >,
  1120.         ) -> GpkgDriver {
  1121.             let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
  1122.                 feature_iterator,
  1123.             );
  1124.             let feature_iterator_illegal_static_reference = unsafe {
  1125.                 ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
  1126.             };
  1127.             let current_feature = current_feature_builder(
  1128.                     feature_iterator_illegal_static_reference,
  1129.                 )
  1130.                 .await;
  1131.             Self {
  1132.                 feature_iterator,
  1133.                 current_feature,
  1134.             }
  1135.         }
  1136.         /**(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:
  1137.  
  1138. | Argument | Suggested Use |
  1139. | --- | --- |
  1140. | `feature_iterator` | Directly pass in the value this field should contain |
  1141. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
  1142. */
  1143.         pub(super) fn try_new<Error_>(
  1144.             feature_iterator: OwnedFeatureIterator,
  1145.             current_feature_builder: impl for<'this> ::core::ops::FnOnce(
  1146.                &'this mut OwnedFeatureIterator,
  1147.             ) -> ::core::result::Result<Option<GdalFeature<'this>>, Error_>,
  1148.        ) -> ::core::result::Result<GpkgDriver, Error_> {
  1149.            GpkgDriver::try_new_or_recover(feature_iterator, current_feature_builder)
  1150.                .map_err(|(error, _heads)| error)
  1151.        }
  1152.        /**(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:
  1153.  
  1154. | Argument | Suggested Use |
  1155. | --- | --- |
  1156. | `feature_iterator` | Directly pass in the value this field should contain |
  1157. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
  1158. */
  1159.        pub(super) fn try_new_or_recover<Error_>(
  1160.            feature_iterator: OwnedFeatureIterator,
  1161.            current_feature_builder: impl for<'this> ::core::ops::FnOnce(
  1162.                 &'this mut OwnedFeatureIterator,
  1163.            ) -> ::core::result::Result<Option<GdalFeature<'this>>, Error_>,
  1164.         ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
  1165.             let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
  1166.                 feature_iterator,
  1167.             );
  1168.             let feature_iterator_illegal_static_reference = unsafe {
  1169.                 ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
  1170.             };
  1171.             let current_feature = match current_feature_builder(
  1172.                 feature_iterator_illegal_static_reference,
  1173.             ) {
  1174.                 ::core::result::Result::Ok(value) => value,
  1175.                 ::core::result::Result::Err(err) => {
  1176.                     return ::core::result::Result::Err((
  1177.                         err,
  1178.                         Heads {
  1179.                             feature_iterator: ::ouroboros::macro_help::unbox(
  1180.                                 feature_iterator,
  1181.                             ),
  1182.                         },
  1183.                     ));
  1184.                 }
  1185.             };
  1186.             ::core::result::Result::Ok(Self {
  1187.                 feature_iterator,
  1188.                 current_feature,
  1189.             })
  1190.         }
  1191.         /**(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:
  1192.  
  1193. | Argument | Suggested Use |
  1194. | --- | --- |
  1195. | `feature_iterator` | Directly pass in the value this field should contain |
  1196. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
  1197. */
  1198.         pub(super) async fn try_new_async<Error_>(
  1199.             feature_iterator: OwnedFeatureIterator,
  1200.             current_feature_builder: impl for<'this> ::core::ops::FnOnce(
  1201.                &'this mut OwnedFeatureIterator,
  1202.             ) -> ::core::pin::Pin<
  1203.                     ::ouroboros::macro_help::alloc::boxed::Box<
  1204.                         dyn ::core::future::Future<
  1205.                             Output = ::core::result::Result<
  1206.                                 Option<GdalFeature<'this>>,
  1207.                                Error_,
  1208.                            >,
  1209.                        > + 'this,
  1210.                     >,
  1211.                 >,
  1212.         ) -> ::core::result::Result<GpkgDriver, Error_> {
  1213.             GpkgDriver::try_new_or_recover_async(
  1214.                     feature_iterator,
  1215.                     current_feature_builder,
  1216.                 )
  1217.                 .await
  1218.                 .map_err(|(error, _heads)| error)
  1219.         }
  1220.         /**(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:
  1221.  
  1222. | Argument | Suggested Use |
  1223. | --- | --- |
  1224. | `feature_iterator` | Directly pass in the value this field should contain |
  1225. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
  1226. */
  1227.         pub(super) async fn try_new_or_recover_async<Error_>(
  1228.             feature_iterator: OwnedFeatureIterator,
  1229.             current_feature_builder: impl for<'this> ::core::ops::FnOnce(
  1230.                &'this mut OwnedFeatureIterator,
  1231.             ) -> ::core::pin::Pin<
  1232.                     ::ouroboros::macro_help::alloc::boxed::Box<
  1233.                         dyn ::core::future::Future<
  1234.                             Output = ::core::result::Result<
  1235.                                 Option<GdalFeature<'this>>,
  1236.                                Error_,
  1237.                            >,
  1238.                        > + 'this,
  1239.                     >,
  1240.                 >,
  1241.         ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
  1242.             let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
  1243.                 feature_iterator,
  1244.             );
  1245.             let feature_iterator_illegal_static_reference = unsafe {
  1246.                 ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
  1247.             };
  1248.             let current_feature = match current_feature_builder(
  1249.                     feature_iterator_illegal_static_reference,
  1250.                 )
  1251.                 .await
  1252.             {
  1253.                 ::core::result::Result::Ok(value) => value,
  1254.                 ::core::result::Result::Err(err) => {
  1255.                     return ::core::result::Result::Err((
  1256.                         err,
  1257.                         Heads {
  1258.                             feature_iterator: ::ouroboros::macro_help::unbox(
  1259.                                 feature_iterator,
  1260.                             ),
  1261.                         },
  1262.                     ));
  1263.                 }
  1264.             };
  1265.             ::core::result::Result::Ok(Self {
  1266.                 feature_iterator,
  1267.                 current_feature,
  1268.             })
  1269.         }
  1270.         /**(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:
  1271.  
  1272. | Argument | Suggested Use |
  1273. | --- | --- |
  1274. | `feature_iterator` | Directly pass in the value this field should contain |
  1275. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
  1276. */
  1277.         pub(super) async fn try_new_async_send<Error_>(
  1278.             feature_iterator: OwnedFeatureIterator,
  1279.             current_feature_builder: impl for<'this> ::core::ops::FnOnce(
  1280.                &'this mut OwnedFeatureIterator,
  1281.             ) -> ::core::pin::Pin<
  1282.                     ::ouroboros::macro_help::alloc::boxed::Box<
  1283.                         dyn ::core::future::Future<
  1284.                             Output = ::core::result::Result<
  1285.                                 Option<GdalFeature<'this>>,
  1286.                                Error_,
  1287.                            >,
  1288.                        > + ::core::marker::Send + 'this,
  1289.                     >,
  1290.                 >,
  1291.         ) -> ::core::result::Result<GpkgDriver, Error_> {
  1292.             GpkgDriver::try_new_or_recover_async_send(
  1293.                     feature_iterator,
  1294.                     current_feature_builder,
  1295.                 )
  1296.                 .await
  1297.                 .map_err(|(error, _heads)| error)
  1298.         }
  1299.         /**(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:
  1300.  
  1301. | Argument | Suggested Use |
  1302. | --- | --- |
  1303. | `feature_iterator` | Directly pass in the value this field should contain |
  1304. | `current_feature_builder` | Use a function or closure: `(feature_iterator: &mut _) -> Result<current_feature: _, Error_>` |
  1305. */
  1306.         pub(super) async fn try_new_or_recover_async_send<Error_>(
  1307.             feature_iterator: OwnedFeatureIterator,
  1308.             current_feature_builder: impl for<'this> ::core::ops::FnOnce(
  1309.                &'this mut OwnedFeatureIterator,
  1310.             ) -> ::core::pin::Pin<
  1311.                     ::ouroboros::macro_help::alloc::boxed::Box<
  1312.                         dyn ::core::future::Future<
  1313.                             Output = ::core::result::Result<
  1314.                                 Option<GdalFeature<'this>>,
  1315.                                Error_,
  1316.                            >,
  1317.                        > + ::core::marker::Send + 'this,
  1318.                     >,
  1319.                 >,
  1320.         ) -> ::core::result::Result<GpkgDriver, (Error_, Heads)> {
  1321.             let mut feature_iterator = ::ouroboros::macro_help::aliasable_boxed(
  1322.                 feature_iterator,
  1323.             );
  1324.             let feature_iterator_illegal_static_reference = unsafe {
  1325.                 ::ouroboros::macro_help::change_lifetime_mut(&mut *feature_iterator)
  1326.             };
  1327.             let current_feature = match current_feature_builder(
  1328.                     feature_iterator_illegal_static_reference,
  1329.                 )
  1330.                 .await
  1331.             {
  1332.                 ::core::result::Result::Ok(value) => value,
  1333.                 ::core::result::Result::Err(err) => {
  1334.                     return ::core::result::Result::Err((
  1335.                         err,
  1336.                         Heads {
  1337.                             feature_iterator: ::ouroboros::macro_help::unbox(
  1338.                                 feature_iterator,
  1339.                             ),
  1340.                         },
  1341.                     ));
  1342.                 }
  1343.             };
  1344.             ::core::result::Result::Ok(Self {
  1345.                 feature_iterator,
  1346.                 current_feature,
  1347.             })
  1348.         }
  1349.         ///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).
  1350.         #[inline(always)]
  1351.         pub(super) fn with_current_feature<'outer_borrow, ReturnType>(
  1352.            &'outer_borrow self,
  1353.             user: impl for<'this> ::core::ops::FnOnce(
  1354.                &'outer_borrow Option<GdalFeature<'this>>,
  1355.            ) -> ReturnType,
  1356.        ) -> ReturnType {
  1357.            user(&self.current_feature)
  1358.        }
  1359.        ///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).
  1360.        #[inline(always)]
  1361.        pub(super) fn borrow_current_feature<'this>(
  1362.             &'this self,
  1363.        ) -> &'this Option<GdalFeature<'this>> {
  1364.            &self.current_feature
  1365.        }
  1366.        ///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.
  1367.         #[inline(always)]
  1368.         pub(super) fn with_current_feature_mut<'outer_borrow, ReturnType>(
  1369.            &'outer_borrow mut self,
  1370.             user: impl for<'this> ::core::ops::FnOnce(
  1371.                &'outer_borrow mut Option<GdalFeature<'this>>,
  1372.            ) -> ReturnType,
  1373.        ) -> ReturnType {
  1374.            user(&mut self.current_feature)
  1375.        }
  1376.        ///This method provides immutable references to all [tail and immutably borrowed fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
  1377.        #[inline(always)]
  1378.        pub(super) fn with<'outer_borrow, ReturnType>(
  1379.             &'outer_borrow self,
  1380.            user: impl for<'this> ::core::ops::FnOnce(
  1381.                 BorrowedFields<'outer_borrow, 'this>,
  1382.             ) -> ReturnType,
  1383.         ) -> ReturnType {
  1384.             user(BorrowedFields {
  1385.                 current_feature: &self.current_feature,
  1386.             })
  1387.         }
  1388.         ///This method provides mutable references to all [tail fields](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html#definitions).
  1389.         #[inline(always)]
  1390.         pub(super) fn with_mut<'outer_borrow, ReturnType>(
  1391.            &'outer_borrow mut self,
  1392.             user: impl for<'this> ::core::ops::FnOnce(
  1393.                BorrowedMutFields<'outer_borrow, 'this>,
  1394.            ) -> ReturnType,
  1395.        ) -> ReturnType {
  1396.            user(BorrowedMutFields {
  1397.                current_feature: &mut self.current_feature,
  1398.            })
  1399.        }
  1400.        ///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.
  1401.        #[allow(clippy::drop_ref)]
  1402.        #[allow(clippy::drop_copy)]
  1403.        #[allow(clippy::drop_non_drop)]
  1404.        pub(super) fn into_heads(self) -> Heads {
  1405.            ::core::mem::drop(self.current_feature);
  1406.            let feature_iterator = self.feature_iterator;
  1407.            Heads {
  1408.                feature_iterator: ::ouroboros::macro_help::unbox(feature_iterator),
  1409.            }
  1410.        }
  1411.    }
  1412.    fn type_asserts() {}
  1413. }
  1414. pub use ouroboros_impl_gpkg_driver::GpkgDriver;
  1415. use ouroboros_impl_gpkg_driver::GpkgDriverBuilder;
  1416. use ouroboros_impl_gpkg_driver::GpkgDriverAsyncBuilder;
  1417. use ouroboros_impl_gpkg_driver::GpkgDriverAsyncSendBuilder;
  1418. use ouroboros_impl_gpkg_driver::GpkgDriverTryBuilder;
  1419. use ouroboros_impl_gpkg_driver::GpkgDriverAsyncTryBuilder;
  1420. use ouroboros_impl_gpkg_driver::GpkgDriverAsyncSendTryBuilder;
  1421. impl<'a> Driver for GpkgDriver {
  1422.     fn can_open(path: &str) -> bool {
  1423.         let re = Regex::new(
  1424.                 r"^(?P<file_path>(?:.*/)?(?P<file_name>(?:.*/)?(?P<file_own_name>.*)\.(?P<extension>gpkg)))(?::(?P<layer_name>[a-z0-9_-]+))?$",
  1425.             )
  1426.             .unwrap();
  1427.         re.is_match(&path)
  1428.     }
  1429.     fn open(path: &str) -> Result<Self, Box<dyn Error>> {
  1430.         let dataset = Dataset::open(path)?;
  1431.         let layer = dataset.into_layer(0)?;
  1432.         let feature_iterator = layer.owned_features();
  1433.         GpkgDriverTryBuilder {
  1434.             feature_iterator,
  1435.             current_feature_builder: |fi| Ok(None),
  1436.         }
  1437.             .try_build()
  1438.     }
  1439.     fn forward(&mut self) -> Result<bool, Box<dyn Error>> {
  1440.         if let Some(f) = self.with_feature_iterator().next() {
  1441.             self.borrow_current_feature().replace(f);
  1442.             Ok(true)
  1443.         } else {
  1444.             Ok(false)
  1445.         }
  1446.     }
  1447.     fn get_field_i64(&self, field_name: &str) -> Result<Option<i64>, Box<dyn Error>> {
  1448.         Ok(Some(123))
  1449.     }
  1450.     fn get_field_point(
  1451.         &self,
  1452.         _field_name: &str,
  1453.     ) -> Result<Option<Point>, Box<dyn Error>> {
  1454.         Ok(Some(Point::from((12.3, 45.6))))
  1455.     }
  1456. }
  1457. struct MyStruct {
  1458.     x: i64,
  1459.     geometry: Point,
  1460. }
  1461. #[automatically_derived]
  1462. impl ::core::fmt::Debug for MyStruct {
  1463.     fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
  1464.         ::core::fmt::Formatter::debug_struct_field2_finish(
  1465.             f,
  1466.             "MyStruct",
  1467.             "x",
  1468.             &&self.x,
  1469.             "geometry",
  1470.             &&self.geometry,
  1471.         )
  1472.     }
  1473. }
  1474. struct MyStructIter(Box<dyn Driver>);
  1475. impl<'a> MyStruct {
  1476.    fn iter_from(driver: Box<dyn Driver>) -> MyStructIter {
  1477.        MyStructIter(driver)
  1478.    }
  1479. }
  1480. impl MyStructIter {
  1481.    fn next_(&mut self) -> Result<Option<MyStruct>, Box<dyn Error>> {
  1482.        if !self.0.forward()? {
  1483.            return Ok(None);
  1484.        }
  1485.        Ok(
  1486.            Some(MyStruct {
  1487.                x: self.0.get_field_i64("x")?.unwrap(),
  1488.                geometry: self.0.get_field_point("geometry")?.unwrap(),
  1489.            }),
  1490.        )
  1491.    }
  1492. }
  1493. impl Iterator for MyStructIter {
  1494.    type Item = Result<MyStruct, Box<dyn Error>>;
  1495.    fn next(&mut self) -> Option<Self::Item> {
  1496.        self.next_().transpose()
  1497.    }
  1498. }
  1499. fn main() -> Result<(), Box<dyn Error>> {
  1500.    let t = Box::new(FgbDriver::open("local.fgb")?) as Box<dyn Driver>;
  1501.    for item in MyStruct::iter_from(t) {
  1502.        let item = item?;
  1503.    }
  1504.    Ok(())
  1505. }
  1506.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement