1
+ use crate :: cxx_string:: CxxString ;
1
2
use std:: ffi:: c_void;
2
3
use std:: fmt:: { self , Display } ;
3
4
use std:: marker:: PhantomData ;
@@ -129,16 +130,16 @@ pub unsafe trait VectorElement: Sized {
129
130
unsafe fn __unique_ptr_drop ( repr : * mut c_void ) ;
130
131
}
131
132
132
- macro_rules! impl_vector_element_for_primitive {
133
- ( $ty: ident ) => {
133
+ macro_rules! impl_vector_element {
134
+ ( $segment : expr , $name : expr , $ ty: ty ) => {
134
135
const_assert_eq!( 1 , mem:: align_of:: <CxxVector <$ty>>( ) ) ;
135
136
136
137
unsafe impl VectorElement for $ty {
137
- const __NAME: & ' static dyn Display = & stringify! ( $ty ) ;
138
+ const __NAME: & ' static dyn Display = & $name ;
138
139
fn __vector_size( v: & CxxVector <$ty>) -> usize {
139
140
extern "C" {
140
141
attr! {
141
- #[ link_name = concat!( "cxxbridge03$std$vector$" , stringify! ( $ty ) , "$size" ) ]
142
+ #[ link_name = concat!( "cxxbridge03$std$vector$" , $segment , "$size" ) ]
142
143
fn __vector_size( _: & CxxVector <$ty>) -> usize ;
143
144
}
144
145
}
@@ -147,7 +148,7 @@ macro_rules! impl_vector_element_for_primitive {
147
148
unsafe fn __get_unchecked( v: & CxxVector <$ty>, pos: usize ) -> & $ty {
148
149
extern "C" {
149
150
attr! {
150
- #[ link_name = concat!( "cxxbridge03$std$vector$" , stringify! ( $ty ) , "$get_unchecked" ) ]
151
+ #[ link_name = concat!( "cxxbridge03$std$vector$" , $segment , "$get_unchecked" ) ]
151
152
fn __get_unchecked( _: & CxxVector <$ty>, _: usize ) -> * const $ty;
152
153
}
153
154
}
@@ -156,7 +157,7 @@ macro_rules! impl_vector_element_for_primitive {
156
157
fn __unique_ptr_null( ) -> * mut c_void {
157
158
extern "C" {
158
159
attr! {
159
- #[ link_name = concat!( "cxxbridge03$unique_ptr$std$vector$" , stringify! ( $ty ) , "$null" ) ]
160
+ #[ link_name = concat!( "cxxbridge03$unique_ptr$std$vector$" , $segment , "$null" ) ]
160
161
fn __unique_ptr_null( this: * mut * mut c_void) ;
161
162
}
162
163
}
@@ -167,7 +168,7 @@ macro_rules! impl_vector_element_for_primitive {
167
168
unsafe fn __unique_ptr_raw( raw: * mut CxxVector <Self >) -> * mut c_void {
168
169
extern "C" {
169
170
attr! {
170
- #[ link_name = concat!( "cxxbridge03$unique_ptr$std$vector$" , stringify! ( $ty ) , "$raw" ) ]
171
+ #[ link_name = concat!( "cxxbridge03$unique_ptr$std$vector$" , $segment , "$raw" ) ]
171
172
fn __unique_ptr_raw( this: * mut * mut c_void, raw: * mut CxxVector <$ty>) ;
172
173
}
173
174
}
@@ -178,7 +179,7 @@ macro_rules! impl_vector_element_for_primitive {
178
179
unsafe fn __unique_ptr_get( repr: * mut c_void) -> * const CxxVector <Self > {
179
180
extern "C" {
180
181
attr! {
181
- #[ link_name = concat!( "cxxbridge03$unique_ptr$std$vector$" , stringify! ( $ty ) , "$get" ) ]
182
+ #[ link_name = concat!( "cxxbridge03$unique_ptr$std$vector$" , $segment , "$get" ) ]
182
183
fn __unique_ptr_get( this: * const * mut c_void) -> * const CxxVector <$ty>;
183
184
}
184
185
}
@@ -187,7 +188,7 @@ macro_rules! impl_vector_element_for_primitive {
187
188
unsafe fn __unique_ptr_release( mut repr: * mut c_void) -> * mut CxxVector <Self > {
188
189
extern "C" {
189
190
attr! {
190
- #[ link_name = concat!( "cxxbridge03$unique_ptr$std$vector$" , stringify! ( $ty ) , "$release" ) ]
191
+ #[ link_name = concat!( "cxxbridge03$unique_ptr$std$vector$" , $segment , "$release" ) ]
191
192
fn __unique_ptr_release( this: * mut * mut c_void) -> * mut CxxVector <$ty>;
192
193
}
193
194
}
@@ -196,7 +197,7 @@ macro_rules! impl_vector_element_for_primitive {
196
197
unsafe fn __unique_ptr_drop( mut repr: * mut c_void) {
197
198
extern "C" {
198
199
attr! {
199
- #[ link_name = concat!( "cxxbridge03$unique_ptr$std$vector$" , stringify! ( $ty ) , "$drop" ) ]
200
+ #[ link_name = concat!( "cxxbridge03$unique_ptr$std$vector$" , $segment , "$drop" ) ]
200
201
fn __unique_ptr_drop( this: * mut * mut c_void) ;
201
202
}
202
203
}
@@ -206,6 +207,12 @@ macro_rules! impl_vector_element_for_primitive {
206
207
} ;
207
208
}
208
209
210
+ macro_rules! impl_vector_element_for_primitive {
211
+ ( $ty: ident) => {
212
+ impl_vector_element!( stringify!( $ty) , stringify!( $ty) , $ty) ;
213
+ } ;
214
+ }
215
+
209
216
impl_vector_element_for_primitive ! ( u8 ) ;
210
217
impl_vector_element_for_primitive ! ( u16 ) ;
211
218
impl_vector_element_for_primitive ! ( u32 ) ;
@@ -218,3 +225,5 @@ impl_vector_element_for_primitive!(i64);
218
225
impl_vector_element_for_primitive ! ( isize ) ;
219
226
impl_vector_element_for_primitive ! ( f32 ) ;
220
227
impl_vector_element_for_primitive ! ( f64 ) ;
228
+
229
+ impl_vector_element ! ( "string" , "CxxString" , CxxString ) ;
0 commit comments