1
1
use crate :: frame:: types;
2
- use bytes:: BufMut ;
2
+ use bytes:: { BufMut , Bytes } ;
3
3
use std:: borrow:: Cow ;
4
4
use std:: collections:: { BTreeMap , BTreeSet , HashMap , HashSet } ;
5
5
use std:: convert:: TryInto ;
@@ -231,32 +231,24 @@ impl std::hash::Hash for CqlTimeuuid {
231
231
/// The implementation of [`PartialEq`], however, normalizes the underlying bytes
232
232
/// before comparison. For details, check [examples](#impl-PartialEq-for-CqlVarint).
233
233
#[ derive( Clone , Eq , Debug ) ]
234
- pub struct CqlVarint ( Vec < u8 > ) ;
234
+ pub struct CqlVarint ( Bytes ) ;
235
235
236
236
/// Constructors from bytes
237
237
impl CqlVarint {
238
238
/// Creates a [`CqlVarint`] from an array of bytes in
239
239
/// two's complement big-endian binary representation.
240
240
///
241
241
/// See: disclaimer about [non-normalized values](CqlVarint#db-data-format).
242
- pub fn from_signed_bytes_be ( digits : Vec < u8 > ) -> Self {
243
- Self ( digits)
244
- }
245
-
246
- /// Creates a [`CqlVarint`] from a slice of bytes in
247
- /// two's complement binary big-endian representation.
248
- ///
249
- /// See: disclaimer about [non-normalized values](CqlVarint#db-data-format).
250
- pub fn from_signed_bytes_be_slice ( digits : & [ u8 ] ) -> Self {
251
- Self :: from_signed_bytes_be ( digits. to_vec ( ) )
242
+ pub fn from_signed_bytes_be ( digits : impl Into < Bytes > ) -> Self {
243
+ Self ( digits. into ( ) )
252
244
}
253
245
}
254
246
255
247
/// Conversion to bytes
256
248
impl CqlVarint {
257
249
/// Converts [`CqlVarint`] to an array of bytes in two's
258
250
/// complement binary big-endian representation.
259
- pub fn into_signed_bytes_be ( self ) -> Vec < u8 > {
251
+ pub fn into_signed_bytes_be ( self ) -> Bytes {
260
252
self . 0
261
253
}
262
254
@@ -269,7 +261,7 @@ impl CqlVarint {
269
261
270
262
impl CqlVarint {
271
263
fn as_normalized_slice ( & self ) -> & [ u8 ] {
272
- let digits = self . 0 . as_slice ( ) ;
264
+ let digits = self . as_signed_bytes_be_slice ( ) ;
273
265
if digits. is_empty ( ) {
274
266
// num-bigint crate normalizes empty vector to 0.
275
267
// We will follow the same approach.
@@ -332,7 +324,7 @@ impl std::hash::Hash for CqlVarint {
332
324
#[ cfg( feature = "num-bigint-03" ) ]
333
325
impl From < num_bigint_03:: BigInt > for CqlVarint {
334
326
fn from ( value : num_bigint_03:: BigInt ) -> Self {
335
- Self ( value. to_signed_bytes_be ( ) )
327
+ Self :: from_signed_bytes_be ( value. to_signed_bytes_be ( ) )
336
328
}
337
329
}
338
330
@@ -346,7 +338,7 @@ impl From<CqlVarint> for num_bigint_03::BigInt {
346
338
#[ cfg( feature = "num-bigint-04" ) ]
347
339
impl From < num_bigint_04:: BigInt > for CqlVarint {
348
340
fn from ( value : num_bigint_04:: BigInt ) -> Self {
349
- Self ( value. to_signed_bytes_be ( ) )
341
+ Self :: from_signed_bytes_be ( value. to_signed_bytes_be ( ) )
350
342
}
351
343
}
352
344
@@ -411,7 +403,7 @@ impl CqlDecimal {
411
403
412
404
/// Converts [`CqlDecimal`] to an array of bytes in two's
413
405
/// complement binary big-endian representation and a scale.
414
- pub fn into_signed_be_bytes_and_exponent ( self ) -> ( Vec < u8 > , i32 ) {
406
+ pub fn into_signed_be_bytes_and_exponent ( self ) -> ( Bytes , i32 ) {
415
407
( self . int_val . into_signed_bytes_be ( ) , self . scale )
416
408
}
417
409
}
0 commit comments