@@ -9,28 +9,34 @@ use pyo3::prelude::*;
99use pyo3:: types:: { PyString , PyTuple } ;
1010use pyo3:: { intern, IntoPyObjectExt } ;
1111
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 ) ;
1914
2015impl From < Endianness > for PyEndianness {
2116 fn from ( value : Endianness ) -> Self {
22- match value {
23- Endianness :: LittleEndian => Self :: LittleEndian ,
24- Endianness :: BigEndian => Self :: BigEndian ,
25- }
17+ Self ( value)
2618 }
2719}
2820
2921impl From < PyEndianness > for Endianness {
3022 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" ) ) ,
3440 }
3541 }
3642}
0 commit comments