@@ -5,12 +5,14 @@ use std::{
5
5
6
6
use crate :: {
7
7
bson:: { Bson , Document , RawArrayBuf , RawBson , RawBsonRef , RawDocumentBuf } ,
8
+ checked:: Checked ,
8
9
error:: { ErrorKind , Result } ,
9
10
runtime:: SyncLittleEndianRead ,
10
11
} ;
11
12
12
13
/// Coerce numeric types into an `i64` if it would be lossless to do so. If this Bson is not numeric
13
14
/// or the conversion would be lossy (e.g. 1.5 -> 1), this returns `None`.
15
+ #[ allow( clippy:: cast_possible_truncation) ]
14
16
pub ( crate ) fn get_int ( val : & Bson ) -> Option < i64 > {
15
17
match * val {
16
18
Bson :: Int32 ( i) => Some ( i64:: from ( i) ) ,
@@ -33,6 +35,7 @@ pub(crate) fn get_int_raw(val: RawBsonRef<'_>) -> Option<i64> {
33
35
34
36
/// Coerce numeric types into an `u64` if it would be lossless to do so. If this Bson is not numeric
35
37
/// or the conversion would be lossy (e.g. 1.5 -> 1), this returns `None`.
38
+ #[ allow( clippy:: cast_possible_truncation) ]
36
39
pub ( crate ) fn get_u64 ( val : & Bson ) -> Option < u64 > {
37
40
match * val {
38
41
Bson :: Int32 ( i) => u64:: try_from ( i) . ok ( ) ,
@@ -89,18 +92,18 @@ pub(crate) fn update_document_check(update: &Document) -> Result<()> {
89
92
}
90
93
91
94
/// The size in bytes of the provided document's entry in a BSON array at the given index.
92
- pub ( crate ) fn array_entry_size_bytes ( index : usize , doc_len : usize ) -> u64 {
95
+ pub ( crate ) fn array_entry_size_bytes ( index : usize , doc_len : usize ) -> Result < usize > {
93
96
// * type (1 byte)
94
97
// * number of decimal digits in key
95
98
// * null terminator for the key (1 byte)
96
99
// * size of value
97
100
98
- 1 + num_decimal_digits ( index) + 1 + doc_len as u64
101
+ ( Checked :: new ( 1 ) + num_decimal_digits ( index) + 1 + doc_len) . get ( )
99
102
}
100
103
101
104
/// The number of digits in `n` in base 10.
102
105
/// Useful for calculating the size of an array entry in BSON.
103
- fn num_decimal_digits ( mut n : usize ) -> u64 {
106
+ fn num_decimal_digits ( mut n : usize ) -> usize {
104
107
let mut digits = 0 ;
105
108
106
109
loop {
0 commit comments