@@ -62,9 +62,9 @@ use tracing::Instrument;
6262/// ```
6363#[ derive( Clone ) ]
6464pub struct CouchbaseList < ' a > {
65- pub collection : & ' a Collection ,
66- pub id : String ,
67- pub options : CouchbaseListOptions ,
65+ collection : & ' a Collection ,
66+ id : String ,
67+ options : CouchbaseListOptions ,
6868}
6969
7070impl Collection {
@@ -250,11 +250,11 @@ impl CouchbaseList<'_> {
250250 result
251251 }
252252
253- /// Returns the index of the first occurrence of the given value, or `-1 ` if not found.
253+ /// Returns the index of the first occurrence of the given value, or `None ` if not found.
254254 pub async fn position < V : PartialEq + DeserializeOwned > (
255255 & self ,
256- value : V ,
257- ) -> crate :: error:: Result < isize > {
256+ value : & V ,
257+ ) -> crate :: error:: Result < Option < usize > > {
258258 let ctx = self
259259 . collection
260260 . tracing_client
@@ -267,12 +267,7 @@ impl CouchbaseList<'_> {
267267 let result = async {
268268 let get_res = self . collection . get ( & self . id , None ) . await ?;
269269 let list_contents: Vec < V > = get_res. content_as ( ) ?;
270- for ( i, item) in list_contents. iter ( ) . enumerate ( ) {
271- if * item == value {
272- return Ok ( i as isize ) ;
273- }
274- }
275- Ok ( -1 )
270+ Ok ( list_contents. iter ( ) . position ( |item| item == value) )
276271 }
277272 . instrument ( ctx. span ( ) . clone ( ) )
278273 . await ;
@@ -304,6 +299,11 @@ impl CouchbaseList<'_> {
304299 result
305300 }
306301
302+ /// Returns `true` if the list contains no elements.
303+ pub async fn is_empty ( & self ) -> crate :: error:: Result < bool > {
304+ Ok ( self . len ( ) . await ? == 0 )
305+ }
306+
307307 /// Removes all elements from the list by deleting the backing document.
308308 pub async fn clear ( & self ) -> crate :: error:: Result < ( ) > {
309309 let ctx = self
@@ -331,9 +331,9 @@ impl CouchbaseList<'_> {
331331/// Supports get, insert, remove, keys, values, exists, size, clear, and iteration.
332332#[ derive( Clone ) ]
333333pub struct CouchbaseMap < ' a > {
334- pub collection : & ' a Collection ,
335- pub id : String ,
336- pub options : CouchbaseMapOptions ,
334+ collection : & ' a Collection ,
335+ id : String ,
336+ options : CouchbaseMapOptions ,
337337}
338338
339339impl CouchbaseMap < ' _ > {
@@ -487,6 +487,11 @@ impl CouchbaseMap<'_> {
487487 result
488488 }
489489
490+ /// Returns `true` if the map contains no entries.
491+ pub async fn is_empty ( & self ) -> crate :: error:: Result < bool > {
492+ Ok ( self . len ( ) . await ? == 0 )
493+ }
494+
490495 /// Returns all keys in the map.
491496 pub async fn keys ( & self ) -> crate :: error:: Result < Vec < String > > {
492497 let ctx = self
@@ -559,9 +564,9 @@ impl CouchbaseMap<'_> {
559564/// Duplicate values are silently ignored.
560565#[ derive( Clone ) ]
561566pub struct CouchbaseSet < ' a > {
562- pub collection : & ' a Collection ,
563- pub id : String ,
564- pub options : CouchbaseSetOptions ,
567+ collection : & ' a Collection ,
568+ id : String ,
569+ options : CouchbaseSetOptions ,
565570}
566571
567572impl CouchbaseSet < ' _ > {
@@ -709,7 +714,7 @@ impl CouchbaseSet<'_> {
709714 /// Returns `true` if the set contains the given value.
710715 pub async fn contains < T : PartialEq + DeserializeOwned > (
711716 & self ,
712- value : T ,
717+ value : & T ,
713718 ) -> crate :: error:: Result < bool > {
714719 let ctx = self
715720 . collection
@@ -723,12 +728,7 @@ impl CouchbaseSet<'_> {
723728 let result = async {
724729 let res = self . collection . get ( & self . id , None ) . await ?;
725730 let set_contents: Vec < T > = res. content_as ( ) ?;
726- for item in set_contents {
727- if item == value {
728- return Ok ( true ) ;
729- }
730- }
731- Ok ( false )
731+ Ok ( set_contents. iter ( ) . any ( |item| item == value) )
732732 }
733733 . instrument ( ctx. span ( ) . clone ( ) )
734734 . await ;
@@ -760,6 +760,11 @@ impl CouchbaseSet<'_> {
760760 result
761761 }
762762
763+ /// Returns `true` if the set contains no elements.
764+ pub async fn is_empty ( & self ) -> crate :: error:: Result < bool > {
765+ Ok ( self . len ( ) . await ? == 0 )
766+ }
767+
763768 /// Removes all elements from the set by deleting the backing document.
764769 pub async fn clear ( & self ) -> crate :: error:: Result < ( ) > {
765770 let ctx = self
@@ -787,9 +792,9 @@ impl CouchbaseSet<'_> {
787792/// Supports push, pop, size, clear, and iteration.
788793#[ derive( Clone ) ]
789794pub struct CouchbaseQueue < ' a > {
790- pub collection : & ' a Collection ,
791- pub id : String ,
792- pub options : CouchbaseQueueOptions ,
795+ collection : & ' a Collection ,
796+ id : String ,
797+ options : CouchbaseQueueOptions ,
793798}
794799
795800impl CouchbaseQueue < ' _ > {
@@ -917,6 +922,11 @@ impl CouchbaseQueue<'_> {
917922 result
918923 }
919924
925+ /// Returns `true` if the queue contains no elements.
926+ pub async fn is_empty ( & self ) -> crate :: error:: Result < bool > {
927+ Ok ( self . len ( ) . await ? == 0 )
928+ }
929+
920930 /// Removes all elements from the queue by deleting the backing document.
921931 pub async fn clear ( & self ) -> crate :: error:: Result < ( ) > {
922932 let ctx = self
0 commit comments