@@ -4,6 +4,7 @@ use std::{borrow::Cow, fs, iter::repeat, path::Path};
44#[ derive( Debug , PartialEq , Eq ) ]
55pub enum InnerVecType {
66 U8 ,
7+ String ,
78 Custom ( String ) ,
89}
910
@@ -157,6 +158,8 @@ impl StructBindGenerator {
157158 let ( rust_type, inner_type) = if raw_type. starts_with ( "Vec<" ) {
158159 if raw_type == "Vec<u8>" {
159160 ( RustType :: Vec ( InnerVecType :: U8 ) , None )
161+ } else if raw_type == "Vec<String>" {
162+ ( RustType :: Vec ( InnerVecType :: String ) , None )
160163 } else {
161164 let inner_type = raw_type
162165 . trim_start_matches ( "Vec<" )
@@ -309,6 +312,7 @@ impl StructBindGenerator {
309312 } else {
310313 format ! ( "Vec<Py<super::{inner_type}>>" )
311314 } ) ,
315+ RustType :: Vec ( InnerVecType :: String ) => Cow :: Borrowed ( "Vec<String>" ) ,
312316 RustType :: Vec ( InnerVecType :: U8 ) => Cow :: Borrowed ( "Py<PyBytes>" ) ,
313317 RustType :: Box ( inner_type) => Cow :: Owned ( if self . is_frozen {
314318 format ! ( "super::{inner_type}" )
@@ -375,8 +379,8 @@ impl StructBindGenerator {
375379 }
376380
377381 fn generate_str_method ( & mut self ) {
378- write_str ! ( self , " pub fn __str__(&self) -> String {" ) ;
379- write_str ! ( self , " format!( \" { self:?} \" )" ) ;
382+ write_str ! ( self , " pub fn __str__(&self, py: Python ) -> String {" ) ;
383+ write_str ! ( self , " self.__repr__(py )" ) ;
380384 write_str ! ( self , " }" ) ;
381385 }
382386
@@ -404,7 +408,7 @@ impl StructBindGenerator {
404408 match & variable_info. rust_type {
405409 RustType :: String => format ! ( "{variable_name}={{:?}}" ) ,
406410 RustType :: Vec ( InnerVecType :: U8 ) => format ! ( "{variable_name}=bytes([{{}}])" ) ,
407- RustType :: Vec ( InnerVecType :: Custom ( _ ) ) => format ! ( "{variable_name}=[{{}}]" ) ,
411+ RustType :: Vec ( _ ) => format ! ( "{variable_name}=[{{}}]" ) ,
408412 _ => format ! ( "{variable_name}={{}}" ) ,
409413 }
410414 } )
@@ -424,6 +428,10 @@ impl StructBindGenerator {
424428 write_str ! ( self , " .iter()" ) ;
425429 write_str ! ( self , " .map(ToString::to_string)" ) ;
426430 }
431+ InnerVecType :: String => {
432+ write_str ! ( self , " .iter()" ) ;
433+ write_str ! ( self , " .map(|s| format!(\" {s:?}\" ))" ) ;
434+ }
427435 InnerVecType :: Custom ( _) => {
428436 write_str ! ( self , " .iter()" ) ;
429437 write_str ! (
@@ -665,6 +673,7 @@ impl Generator for StructBindGenerator {
665673
666674 let variable_type = match & variable_info. rust_type {
667675 RustType :: Vec ( InnerVecType :: U8 ) => String :: from ( "Py<PyBytes>" ) ,
676+ RustType :: Vec ( InnerVecType :: String ) => String :: from ( "Vec<String>" ) ,
668677 RustType :: Vec ( InnerVecType :: Custom ( inner_type) ) => {
669678 if self . is_frozen {
670679 format ! ( "Vec<super::{inner_type}>" )
@@ -717,7 +726,7 @@ impl Generator for StructBindGenerator {
717726
718727 let end = match & variable_info. rust_type {
719728 RustType :: Vec ( InnerVecType :: U8 ) => Cow :: Borrowed ( "PyBytes::new_bound(py, &[]).unbind()" ) ,
720- RustType :: Vec ( InnerVecType :: Custom ( _) ) => Cow :: Borrowed ( "Vec::new()" ) ,
729+ RustType :: Vec ( InnerVecType :: Custom ( _) | InnerVecType :: String ) => Cow :: Borrowed ( "Vec::new()" ) ,
721730 RustType :: Option ( _, _) => Cow :: Borrowed ( "None" ) ,
722731 RustType :: Union ( inner_type) | RustType :: Box ( inner_type) | RustType :: Custom ( inner_type) => {
723732 Cow :: Owned ( format ! ( "super::{inner_type}::py_default(py)" ) )
@@ -778,6 +787,9 @@ impl Generator for StructBindGenerator {
778787 " {variable_name}: PyBytes::new_bound(py, &flat_t.{variable_name}).unbind(),"
779788 )
780789 }
790+ RustType :: Vec ( InnerVecType :: String ) => {
791+ write_fmt ! ( self , " {variable_name}: flat_t.{variable_name}," )
792+ }
781793 RustType :: Vec ( InnerVecType :: Custom ( _) ) => {
782794 if self . is_frozen {
783795 let map_out = if variable_info. frozen_needs_py {
@@ -895,6 +907,9 @@ impl Generator for StructBindGenerator {
895907 " {variable_name}: py_type.{variable_name}.as_bytes(py).to_vec(),"
896908 )
897909 }
910+ RustType :: Vec ( InnerVecType :: String ) => {
911+ write_fmt ! ( self , " {variable_name}: py_type.{variable_name}.clone()," )
912+ }
898913 RustType :: Vec ( InnerVecType :: Custom ( _) ) => {
899914 if self . is_frozen {
900915 let map_out = if variable_info. frozen_needs_py {
0 commit comments