@@ -17,37 +17,6 @@ pub use iterator::{ArcMessageIter, RefMessageIter};
1717
1818mod iterator;
1919
20- /// This is an internal structure used to access provided file by `CodesHandle`.
21- /// It also allows to differentiate between `CodesFile` created from file and from index.
22- /// It is not intended to be used directly by the user.
23- #[ doc( hidden) ]
24- #[ derive( Debug ) ]
25- pub struct CodesFileSource < D : Debug > {
26- // fields dropped from top
27- pointer : * mut FILE ,
28- product_kind : ProductKind ,
29- _data : D ,
30- }
31-
32- /// Marker trait to differentiate between `CodesHandle` created from index and file/buffer.
33- #[ doc( hidden) ]
34- pub trait ThreadSafeHandle : HandleGenerator { }
35-
36- impl ThreadSafeHandle for CodesFileSource < Vec < u8 > > { }
37- impl ThreadSafeHandle for CodesFileSource < File > { }
38-
39- /// Internal trait implemented for types that can be called to generate `*mut codes_handle`.
40- #[ doc( hidden) ]
41- pub trait HandleGenerator : Debug {
42- fn gen_codes_handle ( & mut self ) -> Result < * mut codes_handle , CodesError > ;
43- }
44-
45- impl < D : Debug > HandleGenerator for CodesFileSource < D > {
46- fn gen_codes_handle ( & mut self ) -> Result < * mut codes_handle , CodesError > {
47- unsafe { codes_handle_new_from_file ( self . pointer , self . product_kind ) }
48- }
49- }
50-
5120/// Structure providing access to the GRIB file which takes a full ownership of the accessed file.
5221///
5322/// It can be constructed from:
@@ -117,8 +86,11 @@ impl<D: Debug> HandleGenerator for CodesFileSource<D> {
11786///
11887/// All available methods for `CodesHandle` iterator can be found in [`FallibleStreamingIterator`](crate::FallibleStreamingIterator) trait.
11988#[ derive( Debug ) ]
120- pub struct CodesFile < S : HandleGenerator > {
121- source : S ,
89+ pub struct CodesFile < D : Debug > {
90+ // fields are dropped from top
91+ pointer : * mut FILE ,
92+ product_kind : ProductKind ,
93+ _data : D ,
12294}
12395
12496// 2024-07-26
@@ -135,6 +107,12 @@ pub struct CodesFile<S: HandleGenerator> {
135107// Clearing the memory is handled on ecCodes side by KeyedMessage/CodesIndex destructors
136108// and on rust side by destructors of data_container we own.
137109
110+ impl < D : Debug > CodesFile < D > {
111+ fn generate_codes_handle ( & mut self ) -> Result < * mut codes_handle , CodesError > {
112+ unsafe { codes_handle_new_from_file ( self . pointer , self . product_kind ) }
113+ }
114+ }
115+
138116/// Enum representing the kind of product (file type) inside handled file.
139117/// Used to indicate to ecCodes how it should decode/encode messages.
140118#[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash , Debug ) ]
@@ -143,7 +121,7 @@ pub enum ProductKind {
143121 GRIB = ProductKind_PRODUCT_GRIB as isize ,
144122}
145123
146- impl CodesFile < CodesFileSource < File > > {
124+ impl CodesFile < File > {
147125 ///Opens file at given [`Path`] as selected [`ProductKind`] and contructs `CodesHandle`.
148126 ///
149127 ///## Example
@@ -188,15 +166,13 @@ impl CodesFile<CodesFileSource<File>> {
188166 let file_pointer = open_with_fdopen ( & file) ?;
189167
190168 Ok ( Self {
191- source : CodesFileSource {
192- _data : file,
193- pointer : file_pointer,
194- product_kind,
195- } ,
169+ _data : file,
170+ pointer : file_pointer,
171+ product_kind,
196172 } )
197173 }
198174}
199- impl CodesFile < CodesFileSource < Vec < u8 > > > {
175+ impl CodesFile < Vec < u8 > > {
200176 ///Opens data in provided buffer as selected [`ProductKind`] and contructs `CodesHandle`.
201177 ///
202178 ///## Example
@@ -239,11 +215,9 @@ impl CodesFile<CodesFileSource<Vec<u8>>> {
239215 let file_pointer = open_with_fmemopen ( & file_data) ?;
240216
241217 Ok ( Self {
242- source : CodesFileSource {
243- _data : file_data,
244- product_kind,
245- pointer : file_pointer,
246- } ,
218+ _data : file_data,
219+ product_kind,
220+ pointer : file_pointer,
247221 } )
248222 }
249223}
@@ -297,14 +271,14 @@ mod tests {
297271 let file_path = Path :: new ( "./data/iceland.grib" ) ;
298272 let product_kind = ProductKind :: GRIB ;
299273
300- let handle = CodesFile :: new_from_file ( file_path, product_kind) ?;
274+ let codes_file = CodesFile :: new_from_file ( file_path, product_kind) ?;
301275
302- assert ! ( !handle . source . pointer. is_null( ) ) ;
303- assert_eq ! ( handle . source . product_kind as u32 , {
276+ assert ! ( !codes_file . pointer. is_null( ) ) ;
277+ assert_eq ! ( codes_file . product_kind as u32 , {
304278 ProductKind_PRODUCT_GRIB
305279 } ) ;
306280
307- handle . source . _data . metadata ( ) ?;
281+ codes_file . _data . metadata ( ) ?;
308282
309283 Ok ( ( ) )
310284 }
@@ -317,13 +291,13 @@ mod tests {
317291 let mut buf = Vec :: new ( ) ;
318292 f. read_to_end ( & mut buf) ?;
319293
320- let handle = CodesFile :: new_from_memory ( buf, product_kind) ?;
321- assert ! ( !handle . source . pointer. is_null( ) ) ;
322- assert_eq ! ( handle . source . product_kind as u32 , {
294+ let codes_file = CodesFile :: new_from_memory ( buf, product_kind) ?;
295+ assert ! ( !codes_file . pointer. is_null( ) ) ;
296+ assert_eq ! ( codes_file . product_kind as u32 , {
323297 ProductKind_PRODUCT_GRIB
324298 } ) ;
325299
326- assert ! ( !handle . source . _data. is_empty( ) ) ;
300+ assert ! ( !codes_file . _data. is_empty( ) ) ;
327301
328302 Ok ( ( ) )
329303 }
0 commit comments