Skip to content

RUST-1881 #1047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,794 changes: 0 additions & 2,794 deletions .evergreen/MSRV-Cargo.lock

This file was deleted.

18 changes: 18 additions & 0 deletions .evergreen/MSRV-Cargo.toml.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
95c95
< bson = "2.8.0"
---
> bson = "=2.8.0"
103a104
> hashbrown = "=0.12.3"
166c167
< version = "1.17.0"
---
> version = "=1.18.0"
193c194
< serde_json = "1.0.64"
---
> serde_json = "=1.0.64"
195c196
< time = "0.3.9"
---
> time = "=0.3.9"
2 changes: 1 addition & 1 deletion .evergreen/compile-only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ source ./.evergreen/env.sh
if [ "$RUST_VERSION" != "" ]; then
rustup toolchain install $RUST_VERSION
TOOLCHAIN="+${RUST_VERSION}"
cp .evergreen/MSRV-Cargo.lock Cargo.lock
patch Cargo.toml .evergreen/MSRV-Cargo.toml.diff
fi

source ./.evergreen/feature-combinations.sh
Expand Down
9 changes: 6 additions & 3 deletions src/bson_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ use std::{

use crate::{
bson::{Bson, Document, RawArrayBuf, RawBson, RawBsonRef, RawDocumentBuf},
checked::Checked,
error::{ErrorKind, Result},
runtime::SyncLittleEndianRead,
};

/// Coerce numeric types into an `i64` if it would be lossless to do so. If this Bson is not numeric
/// or the conversion would be lossy (e.g. 1.5 -> 1), this returns `None`.
#[allow(clippy::cast_possible_truncation)]
pub(crate) fn get_int(val: &Bson) -> Option<i64> {
match *val {
Bson::Int32(i) => Some(i64::from(i)),
Expand All @@ -33,6 +35,7 @@ pub(crate) fn get_int_raw(val: RawBsonRef<'_>) -> Option<i64> {

/// Coerce numeric types into an `u64` if it would be lossless to do so. If this Bson is not numeric
/// or the conversion would be lossy (e.g. 1.5 -> 1), this returns `None`.
#[allow(clippy::cast_possible_truncation)]
pub(crate) fn get_u64(val: &Bson) -> Option<u64> {
match *val {
Bson::Int32(i) => u64::try_from(i).ok(),
Expand Down Expand Up @@ -89,18 +92,18 @@ pub(crate) fn update_document_check(update: &Document) -> Result<()> {
}

/// The size in bytes of the provided document's entry in a BSON array at the given index.
pub(crate) fn array_entry_size_bytes(index: usize, doc_len: usize) -> u64 {
pub(crate) fn array_entry_size_bytes(index: usize, doc_len: usize) -> Result<usize> {
// * type (1 byte)
// * number of decimal digits in key
// * null terminator for the key (1 byte)
// * size of value

1 + num_decimal_digits(index) + 1 + doc_len as u64
(Checked::new(1) + num_decimal_digits(index) + 1 + doc_len).get()
}

/// The number of digits in `n` in base 10.
/// Useful for calculating the size of an array entry in BSON.
fn num_decimal_digits(mut n: usize) -> u64 {
fn num_decimal_digits(mut n: usize) -> usize {
let mut digits = 0;

loop {
Expand Down
Loading