@@ -249,7 +249,7 @@ impl<'a: 'b, 'b> From<&'a BatchStatement>
249
249
}
250
250
251
251
/// A batch with all of its statements bound to values
252
- pub ( crate ) struct BoundBatch {
252
+ pub struct BoundBatch {
253
253
pub ( crate ) config : StatementConfig ,
254
254
batch_type : BatchType ,
255
255
pub ( crate ) buffer : Vec < u8 > ,
@@ -259,21 +259,26 @@ pub(crate) struct BoundBatch {
259
259
}
260
260
261
261
impl BoundBatch {
262
+ pub fn new ( batch_type : BatchType ) -> Self {
263
+ Self {
264
+ batch_type,
265
+ ..Default :: default ( )
266
+ }
267
+ }
268
+
262
269
pub ( crate ) fn from_batch (
263
270
batch : & Batch ,
264
271
values : impl BatchValues ,
265
272
) -> Result < Self , ExecutionError > {
266
273
let mut bound_batch = BoundBatch {
267
274
config : batch. config . clone ( ) ,
268
275
batch_type : batch. batch_type ,
269
- prepared : HashMap :: new ( ) ,
270
- buffer : vec ! [ ] ,
271
- first_prepared : None ,
272
276
statements_len : batch. statements . len ( ) . try_into ( ) . map_err ( |_| {
273
277
ExecutionError :: BadQuery ( BadQuery :: TooManyQueriesInBatchStatement (
274
278
batch. statements . len ( ) ,
275
279
) )
276
280
} ) ?,
281
+ ..Default :: default ( )
277
282
} ;
278
283
279
284
let mut values = values. batch_values_iter ( ) ;
@@ -353,17 +358,17 @@ impl BoundBatch {
353
358
}
354
359
355
360
/// Borrows the execution profile handle associated with this batch.
356
- pub ( crate ) fn get_execution_profile_handle ( & self ) -> Option < & ExecutionProfileHandle > {
361
+ pub fn get_execution_profile_handle ( & self ) -> Option < & ExecutionProfileHandle > {
357
362
self . config . execution_profile_handle . as_ref ( )
358
363
}
359
364
360
365
/// Gets the default timestamp for this batch in microseconds.
361
- pub ( crate ) fn get_timestamp ( & self ) -> Option < i64 > {
366
+ pub fn get_timestamp ( & self ) -> Option < i64 > {
362
367
self . config . timestamp
363
368
}
364
369
365
370
/// Gets type of batch.
366
- pub ( crate ) fn get_type ( & self ) -> BatchType {
371
+ pub fn get_type ( & self ) -> BatchType {
367
372
self . batch_type
368
373
}
369
374
@@ -422,6 +427,19 @@ fn serialize_statement<T>(
422
427
Ok ( Some ( res) )
423
428
}
424
429
430
+ impl Default for BoundBatch {
431
+ fn default ( ) -> Self {
432
+ Self {
433
+ config : StatementConfig :: default ( ) ,
434
+ batch_type : BatchType :: Logged ,
435
+ buffer : Vec :: new ( ) ,
436
+ prepared : HashMap :: new ( ) ,
437
+ first_prepared : None ,
438
+ statements_len : 0 ,
439
+ }
440
+ }
441
+ }
442
+
425
443
fn counts_mismatch_err ( n_value_lists : usize , n_statements : u16 ) -> BatchSerializationError {
426
444
BatchSerializationError :: ValuesAndStatementsLengthMismatch {
427
445
n_value_lists,
0 commit comments