@@ -9,28 +9,34 @@ use pyo3::prelude::*;
9
9
use pyo3:: types:: { PyString , PyTuple } ;
10
10
use pyo3:: { intern, IntoPyObjectExt } ;
11
11
12
- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
13
- #[ pyclass( eq, eq_int, name = "Endianness" ) ]
14
- #[ repr( u16 ) ]
15
- pub ( crate ) enum PyEndianness {
16
- LittleEndian = 0x4949 , // b"II"
17
- BigEndian = 0x4D4D , // b"MM"
18
- }
12
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
13
+ pub ( crate ) struct PyEndianness ( Endianness ) ;
19
14
20
15
impl From < Endianness > for PyEndianness {
21
16
fn from ( value : Endianness ) -> Self {
22
- match value {
23
- Endianness :: LittleEndian => Self :: LittleEndian ,
24
- Endianness :: BigEndian => Self :: BigEndian ,
25
- }
17
+ Self ( value)
26
18
}
27
19
}
28
20
29
21
impl From < PyEndianness > for Endianness {
30
22
fn from ( value : PyEndianness ) -> Self {
31
- match value {
32
- PyEndianness :: LittleEndian => Self :: LittleEndian ,
33
- PyEndianness :: BigEndian => Self :: BigEndian ,
23
+ value. 0
24
+ }
25
+ }
26
+
27
+ impl < ' py > IntoPyObject < ' py > for PyEndianness {
28
+ type Target = PyAny ;
29
+ type Output = Bound < ' py , PyAny > ;
30
+ type Error = PyErr ;
31
+
32
+ fn into_pyobject ( self , py : Python < ' py > ) -> Result < Self :: Output , Self :: Error > {
33
+ // import the python module
34
+ let enums_mod = py. import ( intern ! ( py, "async_tiff.enums" ) ) ?;
35
+ // get our python enum
36
+ let enum_cls = enums_mod. getattr ( intern ! ( py, "Endianness" ) ) ?;
37
+ match self . 0 {
38
+ Endianness :: LittleEndian => enum_cls. getattr ( intern ! ( py, "LittleEndian" ) ) ,
39
+ Endianness :: BigEndian => enum_cls. getattr ( intern ! ( py, "BigEndian" ) ) ,
34
40
}
35
41
}
36
42
}
0 commit comments