@@ -4,7 +4,7 @@ use crate::{
4
4
bson:: { rawdoc, Document } ,
5
5
cmap:: { Command , RawCommandResponse , StreamDescription } ,
6
6
cursor:: CursorSpecification ,
7
- error:: { ErrorKind , Result } ,
7
+ error:: { Error , Result } ,
8
8
operation:: { CursorBody , OperationWithDefaults , Retryability , SERVER_4_4_0_WIRE_VERSION } ,
9
9
options:: { CursorType , FindOptions , SelectionCriteria } ,
10
10
Namespace ,
@@ -38,21 +38,23 @@ impl OperationWithDefaults for Find {
38
38
Self :: NAME : self . ns. coll. clone( ) ,
39
39
} ;
40
40
41
- if let Some ( ref options) = self . options {
41
+ if let Some ( ref mut options) = self . options {
42
42
// negative limits should be interpreted as request for single batch as per crud spec.
43
43
if options. limit . map ( |limit| limit < 0 ) == Some ( true ) {
44
44
body. append ( "singleBatch" , true ) ;
45
45
}
46
46
47
- if options
48
- . batch_size
49
- . map ( |batch_size| batch_size > i32:: MAX as u32 )
50
- == Some ( true )
51
- {
52
- return Err ( ErrorKind :: InvalidArgument {
53
- message : "The batch size must fit into a signed 32-bit integer" . to_string ( ) ,
47
+ if let Some ( ref mut batch_size) = options. batch_size {
48
+ if i32:: try_from ( * batch_size) . is_err ( ) {
49
+ return Err ( Error :: invalid_argument (
50
+ "the batch size must fit into a signed 32-bit integer" ,
51
+ ) ) ;
52
+ }
53
+ if let Some ( limit) = options. limit . and_then ( |limit| u32:: try_from ( limit) . ok ( ) ) {
54
+ if * batch_size == limit {
55
+ * batch_size += 1 ;
56
+ }
54
57
}
55
- . into ( ) ) ;
56
58
}
57
59
58
60
match options. cursor_type {
0 commit comments