File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -120,6 +120,10 @@ impl FormatSpec {
120120
121121 Ok ( PyTuple :: from ( items) )
122122 }
123+
124+ fn size ( & self ) -> usize {
125+ self . codes . iter ( ) . map ( FormatCode :: size) . sum ( )
126+ }
123127}
124128
125129/// Parse endianness
@@ -413,7 +417,7 @@ where
413417fn struct_calcsize ( fmt : PyStringRef , vm : & VirtualMachine ) -> PyResult < usize > {
414418 let fmt_str = fmt. as_str ( ) ;
415419 let format_spec = FormatSpec :: parse ( fmt_str) . map_err ( |e| vm. new_value_error ( e) ) ?;
416- Ok ( format_spec. codes . iter ( ) . map ( |code| code . size ( ) ) . sum ( ) )
420+ Ok ( format_spec. size ( ) )
417421}
418422
419423#[ pyclass( name = "Struct" ) ]
@@ -442,6 +446,10 @@ impl PyStruct {
442446 fn format ( & self ) -> PyStringRef {
443447 self . fmt_str . clone ( )
444448 }
449+ #[ pyproperty]
450+ fn size ( & self ) -> usize {
451+ self . spec . size ( )
452+ }
445453
446454 #[ pymethod]
447455 fn pack ( & self , args : Args , vm : & VirtualMachine ) -> PyResult < Vec < u8 > > {
You can’t perform that action at this time.
0 commit comments