11mod batch;
22pub mod options;
33
4- use std:: { fmt, fmt:: Debug , sync:: Arc } ;
4+ use std:: { borrow :: Borrow , fmt, fmt:: Debug , sync:: Arc } ;
55
66use futures:: StreamExt ;
77use serde:: {
@@ -539,11 +539,11 @@ where
539539 async fn find_one_and_replace_common (
540540 & self ,
541541 filter : Document ,
542- replacement : T ,
542+ replacement : impl Borrow < T > ,
543543 options : impl Into < Option < FindOneAndReplaceOptions > > ,
544544 session : impl Into < Option < & mut ClientSession > > ,
545545 ) -> Result < Option < T > > {
546- let replacement = to_document ( & replacement) ?;
546+ let replacement = to_document ( replacement. borrow ( ) ) ?;
547547
548548 let mut options = options. into ( ) ;
549549 resolve_options ! ( self , options, [ write_concern] ) ;
@@ -562,7 +562,7 @@ where
562562 pub async fn find_one_and_replace (
563563 & self ,
564564 filter : Document ,
565- replacement : T ,
565+ replacement : impl Borrow < T > ,
566566 options : impl Into < Option < FindOneAndReplaceOptions > > ,
567567 ) -> Result < Option < T > > {
568568 self . find_one_and_replace_common ( filter, replacement, options, None )
@@ -579,7 +579,7 @@ where
579579 pub async fn find_one_and_replace_with_session (
580580 & self ,
581581 filter : Document ,
582- replacement : T ,
582+ replacement : impl Borrow < T > ,
583583 options : impl Into < Option < FindOneAndReplaceOptions > > ,
584584 session : & mut ClientSession ,
585585 ) -> Result < Option < T > > {
@@ -643,13 +643,13 @@ where
643643
644644 async fn insert_many_common (
645645 & self ,
646- docs : impl IntoIterator < Item = T > ,
646+ docs : impl IntoIterator < Item = impl Borrow < T > > ,
647647 options : impl Into < Option < InsertManyOptions > > ,
648648 mut session : Option < & mut ClientSession > ,
649649 ) -> Result < InsertManyResult > {
650650 let docs: ser:: Result < Vec < Document > > = docs
651651 . into_iter ( )
652- . map ( |doc| bson:: to_document ( & doc) )
652+ . map ( |doc| bson:: to_document ( doc. borrow ( ) ) )
653653 . collect ( ) ;
654654 let mut docs: Vec < Document > = docs?;
655655
@@ -739,7 +739,7 @@ where
739739 /// retryable writes.
740740 pub async fn insert_many (
741741 & self ,
742- docs : impl IntoIterator < Item = T > ,
742+ docs : impl IntoIterator < Item = impl Borrow < T > > ,
743743 options : impl Into < Option < InsertManyOptions > > ,
744744 ) -> Result < InsertManyResult > {
745745 self . insert_many_common ( docs, options, None ) . await
@@ -753,7 +753,7 @@ where
753753 /// retryable writes.
754754 pub async fn insert_many_with_session (
755755 & self ,
756- docs : impl IntoIterator < Item = T > ,
756+ docs : impl IntoIterator < Item = impl Borrow < T > > ,
757757 options : impl Into < Option < InsertManyOptions > > ,
758758 session : & mut ClientSession ,
759759 ) -> Result < InsertManyResult > {
@@ -762,11 +762,11 @@ where
762762
763763 async fn insert_one_common (
764764 & self ,
765- doc : T ,
765+ doc : impl Borrow < T > ,
766766 options : impl Into < Option < InsertOneOptions > > ,
767767 session : impl Into < Option < & mut ClientSession > > ,
768768 ) -> Result < InsertOneResult > {
769- let doc = to_document ( & doc) ?;
769+ let doc = to_document ( doc. borrow ( ) ) ?;
770770
771771 let mut options = options. into ( ) ;
772772 resolve_options ! ( self , options, [ write_concern] ) ;
@@ -791,7 +791,7 @@ where
791791 /// retryable writes.
792792 pub async fn insert_one (
793793 & self ,
794- doc : T ,
794+ doc : impl Borrow < T > ,
795795 options : impl Into < Option < InsertOneOptions > > ,
796796 ) -> Result < InsertOneResult > {
797797 self . insert_one_common ( doc, options, None ) . await
@@ -805,7 +805,7 @@ where
805805 /// retryable writes.
806806 pub async fn insert_one_with_session (
807807 & self ,
808- doc : T ,
808+ doc : impl Borrow < T > ,
809809 options : impl Into < Option < InsertOneOptions > > ,
810810 session : & mut ClientSession ,
811811 ) -> Result < InsertOneResult > {
@@ -815,11 +815,11 @@ where
815815 async fn replace_one_common (
816816 & self ,
817817 query : Document ,
818- replacement : T ,
818+ replacement : impl Borrow < T > ,
819819 options : impl Into < Option < ReplaceOptions > > ,
820820 session : impl Into < Option < & mut ClientSession > > ,
821821 ) -> Result < UpdateResult > {
822- let replacement = to_document ( & replacement) ?;
822+ let replacement = to_document ( replacement. borrow ( ) ) ?;
823823
824824 bson_util:: replacement_document_check ( & replacement) ?;
825825
@@ -845,7 +845,7 @@ where
845845 pub async fn replace_one (
846846 & self ,
847847 query : Document ,
848- replacement : T ,
848+ replacement : impl Borrow < T > ,
849849 options : impl Into < Option < ReplaceOptions > > ,
850850 ) -> Result < UpdateResult > {
851851 self . replace_one_common ( query, replacement, options, None )
@@ -862,7 +862,7 @@ where
862862 pub async fn replace_one_with_session (
863863 & self ,
864864 query : Document ,
865- replacement : T ,
865+ replacement : impl Borrow < T > ,
866866 options : impl Into < Option < ReplaceOptions > > ,
867867 session : & mut ClientSession ,
868868 ) -> Result < UpdateResult > {
0 commit comments