File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -107,3 +107,31 @@ macro_rules! jmap {
107107 } ;
108108 ( ) => { compiler_error!( "" ) } ;
109109}
110+
111+ /// Helper macro to build a [`Vec<String>`]
112+ ///
113+ /// Quite a few ORM methods take [`Vec<String>`] as an argument. Using the built-in
114+ /// `vec![]` macro requires that each element is converted into a `String`, which
115+ /// is very cumbersome.
116+ ///
117+ /// Using this macro, we can write:
118+ /// ```
119+ /// # #[cfg(not(feature = "types-only"))]
120+ /// # fn test() {
121+ /// # use odoo_api::svec;
122+ /// let fields = svec!["string", "literals", "without", "to_string()"];
123+ /// # }
124+ /// ```
125+ #[ macro_export]
126+ macro_rules! svec {
127+ [ $( $v: tt) ,* ] => {
128+ {
129+ let mut vec = :: std:: vec:: Vec :: <String >:: new( ) ;
130+ $(
131+ vec. push( $v. to_string( ) ) ;
132+ ) *
133+ vec
134+ }
135+ } ;
136+ ( ) => { compiler_error!( "" ) } ;
137+ }
You can’t perform that action at this time.
0 commit comments