diff --git a/Cargo.toml b/Cargo.toml index ffcd1cd..e3829dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,23 @@ [package] name = "couchbase_lite" -# The first three numbers correspond to the Couchbase Lite C release, the fourth number corresponds to the Doctolib release +description = "Rust bindings for Couchbase Lite C" +# The first three numbers correspond to the Couchbase Lite C release, the fourth number corresponds to the Rust release version = "3.2.1-0" -edition = "2021" + +edition = "2024" + +license-file = "libcblite_enterprise/LICENSE.txt" +keywords = ["couchbase"] +categories = ["database"] +publish = ["couchbase-lite-rust"] [dependencies] -enum_primitive = "*" -tempdir = "*" -lazy_static = "1.4.0" -regex = "1.10.4" +enum_primitive = "0.1.1" + +[dev-dependencies] +lazy_static = "1.5.0" +regex = "1.11.1" +tempdir = "0.3.7" [dev-dependencies.cargo-husky] version = "1" @@ -16,7 +25,7 @@ default-features = false # Disable features which are enabled by default features = ["user-hooks"] [build-dependencies] -bindgen = "0.69.4" +bindgen = "0.71.1" fs_extra = "1.2.0" [lib] diff --git a/build.rs b/build.rs index bb9f050..9205646 100644 --- a/build.rs +++ b/build.rs @@ -23,9 +23,13 @@ // - https://doc.rust-lang.org/cargo/reference/build-scripts.html #[cfg(all(not(feature = "community"), not(feature = "enterprise")))] -compile_error!("You need to have one the following features activated: community, enterprise"); +compile_error!( + "You need to have at least one the following features activated: community, enterprise" +); #[cfg(all(feature = "community", feature = "enterprise"))] -compile_error!("You need to have one the following features activated: community, enterprise"); +compile_error!( + "You need to have at most one the following features activated: community, enterprise" +); extern crate bindgen; extern crate fs_extra; diff --git a/src/blob.rs b/src/blob.rs index 7736065..bfcc660 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -231,11 +231,7 @@ impl std::io::Write for BlobWriter<'_> { data.len(), err, ); - if ok { - data.len() as i32 - } else { - -1 - } + if ok { data.len() as i32 } else { -1 } }) } } diff --git a/src/collection.rs b/src/collection.rs index 5c78916..1efb235 100644 --- a/src/collection.rs +++ b/src/collection.rs @@ -148,19 +148,21 @@ impl Clone for Collection { /// A collection change listener callback, invoked after one or more documents are changed on disk. pub type CollectionChangeListener = Box)>; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn c_collection_change_listener( context: *mut ::std::os::raw::c_void, change: *const CBLCollectionChange, ) { let callback = context as *const CollectionChangeListener; - if let Some(change) = change.as_ref() { - let collection = Collection::reference(change.collection as *mut CBLCollection); - let doc_ids = std::slice::from_raw_parts(change.docIDs, change.numDocs as usize) - .iter() - .filter_map(|doc_id| doc_id.to_string()) - .collect(); - - (*callback)(collection, doc_ids); + unsafe { + if let Some(change) = change.as_ref() { + let collection = Collection::reference(change.collection as *mut CBLCollection); + let doc_ids = std::slice::from_raw_parts(change.docIDs, change.numDocs as usize) + .iter() + .filter_map(|doc_id| doc_id.to_string()) + .collect(); + + (*callback)(collection, doc_ids); + } } } diff --git a/src/database.rs b/src/database.rs index eb63c31..0440135 100644 --- a/src/database.rs +++ b/src/database.rs @@ -132,7 +132,7 @@ enum_from_primitive! { #[deprecated(note = "please use `CollectionChangeListener` on default collection instead")] type DatabaseChangeListener = Box)>; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn c_database_change_listener( context: *mut ::std::os::raw::c_void, db: *const CBLDatabase, @@ -142,26 +142,30 @@ unsafe extern "C" fn c_database_change_listener( let callback = context as *const DatabaseChangeListener; let database = Database::reference(db as *mut CBLDatabase); - let doc_ids = std::slice::from_raw_parts(c_doc_ids, num_docs as usize) - .iter() - .filter_map(|doc_id| doc_id.to_string()) - .collect(); + unsafe { + let doc_ids = std::slice::from_raw_parts(c_doc_ids, num_docs as usize) + .iter() + .filter_map(|doc_id| doc_id.to_string()) + .collect(); - (*callback)(&database, doc_ids); + (*callback)(&database, doc_ids); + } } /// Callback indicating that the database (or an object belonging to it) is ready to call one or more listeners. type BufferNotifications = fn(db: &Database); -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn c_database_buffer_notifications( context: *mut ::std::os::raw::c_void, db: *mut CBLDatabase, ) { - let callback: BufferNotifications = std::mem::transmute(context); + unsafe { + let callback: BufferNotifications = std::mem::transmute(context); - let database = Database::reference(db.cast::()); + let database = Database::reference(db.cast::()); - callback(&database); + callback(&database); + } } /// A connection to an open database @@ -213,11 +217,13 @@ impl Database { unsafe fn _open(name: &str, config_ptr: *const CBLDatabaseConfiguration) -> Result { let mut err = CBLError::default(); - let db_ref = CBLDatabase_Open(from_str(name).get_ref(), config_ptr, &mut err); - if db_ref.is_null() { - return failure(err); + unsafe { + let db_ref = CBLDatabase_Open(from_str(name).get_ref(), config_ptr, &mut err); + if db_ref.is_null() { + return failure(err); + } + Ok(Self::take_ownership(db_ref)) } - Ok(Self::take_ownership(db_ref)) } //////// OTHER STATIC METHODS: diff --git a/src/document.rs b/src/document.rs index 6b12e46..d3c564c 100644 --- a/src/document.rs +++ b/src/document.rs @@ -66,18 +66,20 @@ pub enum ConcurrencyControl { /// (probably by a pull replicator, or by application code on another thread) /// since it was loaded into the CBLDocument being saved. type ConflictHandler = fn(&mut Document, &Document) -> bool; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn c_conflict_handler( context: *mut ::std::os::raw::c_void, document_being_saved: *mut CBLDocument, conflicting_document: *const CBLDocument, ) -> bool { - let callback: ConflictHandler = std::mem::transmute(context); + unsafe { + let callback: ConflictHandler = std::mem::transmute(context); - callback( - &mut Document::reference(document_being_saved), - &Document::reference(conflicting_document as *mut CBLDocument), - ) + callback( + &mut Document::reference(document_being_saved), + &Document::reference(conflicting_document as *mut CBLDocument), + ) + } } /// A document change listener lets you detect changes made to a specific document after they @@ -85,15 +87,17 @@ unsafe extern "C" fn c_conflict_handler( #[deprecated(note = "please use `CollectionDocumentChangeListener` instead")] type DatabaseDocumentChangeListener = Box)>; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn c_database_document_change_listener( context: *mut ::std::os::raw::c_void, db: *const CBLDatabase, c_doc_id: FLString, ) { - let callback = context as *const DatabaseDocumentChangeListener; - let database = Database::reference(db as *mut CBLDatabase); - (*callback)(&database, c_doc_id.to_string()); + unsafe { + let callback = context as *const DatabaseDocumentChangeListener; + let database = Database::reference(db as *mut CBLDatabase); + (*callback)(&database, c_doc_id.to_string()); + } } //////// DATABASE'S DOCUMENT API: @@ -308,15 +312,17 @@ impl Database { /// are persisted to the collection. type CollectionDocumentChangeListener = Box)>; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn c_collection_document_change_listener( context: *mut ::std::os::raw::c_void, change: *const CBLDocumentChange, ) { let callback = context as *const CollectionDocumentChangeListener; - if let Some(change) = change.as_ref() { - let collection = Collection::reference(change.collection as *mut CBLCollection); - (*callback)(collection, change.docID.to_string()); + unsafe { + if let Some(change) = change.as_ref() { + let collection = Collection::reference(change.collection as *mut CBLCollection); + (*callback)(collection, change.docID.to_string()); + } } } diff --git a/src/fleece_mutable.rs b/src/fleece_mutable.rs index 47aa14b..876351f 100644 --- a/src/fleece_mutable.rs +++ b/src/fleece_mutable.rs @@ -86,7 +86,9 @@ impl MutableArray { } pub(crate) unsafe fn adopt(array: FLMutableArray) -> Self { - FLValue_Retain(array as FLValue); + unsafe { + FLValue_Retain(array as FLValue); + } Self { cbl_ref: array } } @@ -278,7 +280,9 @@ impl MutableDict { } pub(crate) unsafe fn adopt(dict: FLMutableDict) -> Self { - FLValue_Retain(dict as FLValue); + unsafe { + FLValue_Retain(dict as FLValue); + } Self { cbl_ref: dict } } diff --git a/src/lib.rs b/src/lib.rs index 10d1314..581d234 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,11 +145,13 @@ pub fn dump_instances() { //////// REFCOUNT SUPPORT (INTERNAL) pub(crate) unsafe fn retain(cbl_ref: *mut T) -> *mut T { - CBL_Retain(cbl_ref.cast::()).cast::() + unsafe { CBL_Retain(cbl_ref.cast::()).cast::() } } pub(crate) unsafe fn release(cbl_ref: *mut T) { - CBL_Release(cbl_ref.cast::()); + unsafe { + CBL_Release(cbl_ref.cast::()); + } } //////// ANDROID INIT diff --git a/src/logging.rs b/src/logging.rs index da3fe2c..d841a7e 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -149,9 +149,11 @@ unsafe extern "C" fn invoke_log_callback( c_level: CBLLogLevel, msg: FLString, ) { - if let Some(cb) = LOG_CALLBACK { - let domain = Domain::from_u8(c_domain).unwrap_or(Domain::None); - let level = Level::from_u8(c_level).unwrap_or(Level::None); - cb(domain, level, msg.as_str().unwrap_or("Empty error")); + unsafe { + if let Some(cb) = LOG_CALLBACK { + let domain = Domain::from_u8(c_domain).unwrap_or(Domain::None); + let level = Level::from_u8(c_level).unwrap_or(Level::None); + cb(domain, level, msg.as_str().unwrap_or("Empty error")); + } } } diff --git a/src/query.rs b/src/query.rs index 43cf8d4..757d196 100644 --- a/src/query.rs +++ b/src/query.rs @@ -41,7 +41,7 @@ pub enum QueryLanguage { type ChangeListener = Box; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn c_query_change_listener( context: *mut ::std::os::raw::c_void, query: *mut CBLQuery, @@ -51,7 +51,9 @@ unsafe extern "C" fn c_query_change_listener( let query = Query::reference(query.cast::()); let token = ListenerToken::new(token); - (*callback)(&query, &token); + unsafe { + (*callback)(&query, &token); + } } /** A compiled database query. */ diff --git a/src/replicator.rs b/src/replicator.rs index 5305648..35a0fb1 100644 --- a/src/replicator.rs +++ b/src/replicator.rs @@ -263,7 +263,7 @@ impl CblRef for ProxySettings { /** A callback that can decide whether a particular document should be pushed or pulled. */ pub type ReplicationFilter = Box bool>; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn c_replication_push_filter( context: *mut ::std::os::raw::c_void, document: *mut CBLDocument, @@ -273,10 +273,12 @@ unsafe extern "C" fn c_replication_push_filter( let document = Document::reference(document.cast::()); let (is_deleted, is_access_removed) = read_document_flags(flags); - (*repl_conf_context) - .push_filter - .as_ref() - .is_some_and(|callback| callback(&document, is_deleted, is_access_removed)) + unsafe { + (*repl_conf_context) + .push_filter + .as_ref() + .is_some_and(|callback| callback(&document, is_deleted, is_access_removed)) + } } unsafe extern "C" fn c_replication_pull_filter( context: *mut ::std::os::raw::c_void, @@ -287,10 +289,12 @@ unsafe extern "C" fn c_replication_pull_filter( let document = Document::reference(document.cast::()); let (is_deleted, is_access_removed) = read_document_flags(flags); - (*repl_conf_context) - .pull_filter - .as_ref() - .is_some_and(|callback| callback(&document, is_deleted, is_access_removed)) + unsafe { + (*repl_conf_context) + .pull_filter + .as_ref() + .is_some_and(|callback| callback(&document, is_deleted, is_access_removed)) + } } fn read_document_flags(flags: CBLDocumentFlags) -> (bool, bool) { (flags & DELETED != 0, flags & ACCESS_REMOVED != 0) @@ -311,25 +315,27 @@ unsafe extern "C" fn c_replication_conflict_resolver( ) -> *const CBLDocument { let repl_conf_context = context as *const ReplicationConfigurationContext; - let doc_id = document_id.to_string().unwrap_or_default(); - let local_document = if local_document.is_null() { - None - } else { - Some(Document::reference(local_document as *mut CBLDocument)) - }; - let remote_document = if remote_document.is_null() { - None - } else { - Some(Document::reference(remote_document as *mut CBLDocument)) - }; + unsafe { + let doc_id = document_id.to_string().unwrap_or_default(); + let local_document = if local_document.is_null() { + None + } else { + Some(Document::reference(local_document as *mut CBLDocument)) + }; + let remote_document = if remote_document.is_null() { + None + } else { + Some(Document::reference(remote_document as *mut CBLDocument)) + }; - (*repl_conf_context) - .conflict_resolver - .as_ref() - .map_or(ptr::null(), |callback| { - callback(&doc_id, local_document, remote_document) - .map_or(ptr::null(), |d| d.get_ref() as *const CBLDocument) - }) + (*repl_conf_context) + .conflict_resolver + .as_ref() + .map_or(ptr::null(), |callback| { + callback(&doc_id, local_document, remote_document) + .map_or(ptr::null(), |d| d.get_ref() as *const CBLDocument) + }) + } } #[derive(Debug, PartialEq)] @@ -353,7 +359,7 @@ pub type DefaultCollectionPropertyEncryptor = fn( kid: Option, error: &Error, ) -> std::result::Result, EncryptionError>; -#[no_mangle] +#[unsafe(no_mangle)] #[cfg(feature = "enterprise")] pub extern "C" fn c_default_collection_property_encryptor( context: *mut ::std::os::raw::c_void, @@ -432,7 +438,7 @@ pub type CollectionPropertyEncryptor = fn( kid: Option, error: &Error, ) -> std::result::Result, EncryptionError>; -#[no_mangle] +#[unsafe(no_mangle)] #[cfg(feature = "enterprise")] pub extern "C" fn c_collection_property_encryptor( context: *mut ::std::os::raw::c_void, @@ -514,7 +520,7 @@ pub type DefaultCollectionPropertyDecryptor = fn( kid: Option, error: &Error, ) -> std::result::Result, EncryptionError>; -#[no_mangle] +#[unsafe(no_mangle)] #[cfg(feature = "enterprise")] pub extern "C" fn c_default_collection_property_decryptor( context: *mut ::std::os::raw::c_void, @@ -593,7 +599,7 @@ pub type CollectionPropertyDecryptor = fn( kid: Option, error: &Error, ) -> std::result::Result, EncryptionError>; -#[no_mangle] +#[unsafe(no_mangle)] #[cfg(feature = "enterprise")] pub extern "C" fn c_collection_property_decryptor( context: *mut ::std::os::raw::c_void, @@ -1128,15 +1134,17 @@ impl From for ReplicatorStatus { /** A callback that notifies you when the replicator's status changes. */ pub type ReplicatorChangeListener = Box; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn c_replicator_change_listener( context: *mut ::std::os::raw::c_void, _replicator: *mut CBLReplicator, status: *const CBLReplicatorStatus, ) { let callback = context as *const ReplicatorChangeListener; - let status: ReplicatorStatus = (*status).into(); - (*callback)(status); + unsafe { + let status: ReplicatorStatus = (*status).into(); + (*callback)(status); + } } /** A callback that notifies you when documents are replicated. */ @@ -1156,20 +1164,22 @@ unsafe extern "C" fn c_replicator_document_change_listener( Direction::Pulled }; - let repl_documents = std::slice::from_raw_parts(documents, num_documents as usize) - .iter() - .filter_map(|document| { - document.ID.to_string().map(|doc_id| ReplicatedDocument { - id: doc_id, - flags: document.flags, - error: check_error(&document.error), - scope: document.scope.to_string(), - collection: document.collection.to_string(), + unsafe { + let repl_documents = std::slice::from_raw_parts(documents, num_documents as usize) + .iter() + .filter_map(|document| { + document.ID.to_string().map(|doc_id| ReplicatedDocument { + id: doc_id, + flags: document.flags, + error: check_error(&document.error), + scope: document.scope.to_string(), + collection: document.collection.to_string(), + }) }) - }) - .collect(); + .collect(); - (*callback)(direction, repl_documents); + (*callback)(direction, repl_documents); + } } /** Flags describing a replicated document. */ diff --git a/src/slice.rs b/src/slice.rs index 0f1637e..70ac65b 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -83,11 +83,10 @@ impl Slice { impl Debug for Slice { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Slice") - .field("dump", unsafe { - &FLData_Dump(self.get_ref()).to_string().unwrap_or_default() - }) - .finish() + unsafe { + let s = FLData_Dump(self.get_ref()).to_string().unwrap_or_default(); + f.debug_struct("Slice").field("dump", &s).finish() + } } } @@ -127,22 +126,24 @@ impl FLSlice { if !self { return None; } - Some(std::slice::from_raw_parts(self.buf.cast::(), self.size)) + Some(unsafe { std::slice::from_raw_parts(self.buf.cast::(), self.size) }) } pub(crate) unsafe fn as_str<'a>(&self) -> Option<&'a str> { - match self.as_byte_array() { - None => None, - Some(b) => str::from_utf8(b).ok(), + unsafe { + match self.as_byte_array() { + None => None, + Some(b) => str::from_utf8(b).ok(), + } } } pub(crate) unsafe fn to_string(self) -> Option { - self.as_str().map(std::string::ToString::to_string) + unsafe { self.as_str().map(std::string::ToString::to_string) } } pub(crate) unsafe fn to_vec(self) -> Option> { - self.as_byte_array().map(std::borrow::ToOwned::to_owned) + unsafe { self.as_byte_array().map(std::borrow::ToOwned::to_owned) } } pub(crate) fn map(&self, f: F) -> Option @@ -189,12 +190,12 @@ impl FLSliceResult { // Consumes & releases self pub unsafe fn to_string(self) -> Option { - self.as_slice().to_string() + unsafe { self.as_slice().to_string() } } // Consumes & releases self pub unsafe fn to_vec(self) -> Option> { - self.as_slice().to_vec() + unsafe { self.as_slice().to_vec() } } } @@ -218,14 +219,16 @@ impl Drop for FLSliceResult { // Convenience to convert a raw `char*` to an unowned `&str` pub unsafe fn to_str<'a>(cstr: *const ::std::os::raw::c_char) -> Cow<'a, str> { - CStr::from_ptr(cstr).to_string_lossy() + unsafe { CStr::from_ptr(cstr).to_string_lossy() } } // Convenience to convert a raw `char*` to an owned String pub unsafe fn to_string(cstr: *const ::std::os::raw::c_char) -> String { - to_str(cstr).to_string() + unsafe { to_str(cstr).to_string() } } pub unsafe fn free_cstr(cstr: *const ::std::os::raw::c_char) { - drop_in_place(cstr as *mut ::std::os::raw::c_char); + unsafe { + drop_in_place(cstr as *mut ::std::os::raw::c_char); + } } diff --git a/tests/collection_tests.rs b/tests/collection_tests.rs index 6df883f..a21986a 100644 --- a/tests/collection_tests.rs +++ b/tests/collection_tests.rs @@ -34,17 +34,20 @@ fn create_delete_scopes_collections() { ); // Get collection - assert!(db - .collection(DEFAULT_NAME.to_string(), DEFAULT_NAME.to_string()) - .unwrap() - .is_some()); - assert!(db - .collection(unknown.clone(), DEFAULT_NAME.to_string()) - .unwrap() - .is_none()); // Invalid collection => None - assert!(db - .collection(DEFAULT_NAME.to_string(), unknown.clone()) - .is_err()); // Invalid scope => Err + assert!( + db.collection(DEFAULT_NAME.to_string(), DEFAULT_NAME.to_string()) + .unwrap() + .is_some() + ); + assert!( + db.collection(unknown.clone(), DEFAULT_NAME.to_string()) + .unwrap() + .is_none() + ); // Invalid collection => None + assert!( + db.collection(DEFAULT_NAME.to_string(), unknown.clone()) + .is_err() + ); // Invalid scope => Err assert_eq!( db.default_collection().unwrap().unwrap().full_name(), db.collection(DEFAULT_NAME.to_string(), DEFAULT_NAME.to_string()) @@ -110,42 +113,50 @@ fn create_delete_scopes_collections() { } // Delete collections - assert!(db - .delete_collection(DEFAULT_NAME.to_string(), unknown.clone()) - .is_err()); // Invalid scope => Err - assert!(db - .delete_collection(unknown.clone(), DEFAULT_NAME.to_string()) - .is_ok()); // Invalid collection => Ok - assert!(db - .delete_collection(unknown.clone(), unknown.clone()) - .is_ok()); // Invalid collection & scope => Ok - - assert!(db - .delete_collection(new_collection_2.clone(), new_scope.clone()) - .is_ok()); + assert!( + db.delete_collection(DEFAULT_NAME.to_string(), unknown.clone()) + .is_err() + ); // Invalid scope => Err + assert!( + db.delete_collection(unknown.clone(), DEFAULT_NAME.to_string()) + .is_ok() + ); // Invalid collection => Ok + assert!( + db.delete_collection(unknown.clone(), unknown.clone()) + .is_ok() + ); // Invalid collection & scope => Ok + + assert!( + db.delete_collection(new_collection_2.clone(), new_scope.clone()) + .is_ok() + ); assert!(db.scope(new_scope.clone()).unwrap().is_none()); assert_eq!(db.scope_names().unwrap(), vec![DEFAULT_NAME]); - assert!(db - .collection(new_collection_2.clone(), new_scope.clone()) - .unwrap() - .is_none()); + assert!( + db.collection(new_collection_2.clone(), new_scope.clone()) + .unwrap() + .is_none() + ); assert_eq!( db.collection_names(new_scope.clone()).unwrap(), Vec::::default() ); - assert!(db - .delete_collection(new_collection_1.clone(), DEFAULT_NAME.to_string()) - .is_ok()); + assert!( + db.delete_collection(new_collection_1.clone(), DEFAULT_NAME.to_string()) + .is_ok() + ); assert!(db.scope(DEFAULT_NAME.to_string()).unwrap().is_some()); // Default scope kept - assert!(db - .collection(new_collection_1.clone(), DEFAULT_NAME.to_string()) - .unwrap() - .is_none()); - - assert!(db - .delete_collection(DEFAULT_NAME.to_string(), DEFAULT_NAME.to_string()) - .is_err()); // Impossible to delete default collection + assert!( + db.collection(new_collection_1.clone(), DEFAULT_NAME.to_string()) + .unwrap() + .is_none() + ); + + assert!( + db.delete_collection(DEFAULT_NAME.to_string(), DEFAULT_NAME.to_string()) + .is_err() + ); // Impossible to delete default collection }); } @@ -301,10 +312,12 @@ fn scope_accessors() { vec![new_collection_2.clone(), new_collection_1.clone()] ); - assert!(default_scope - .collection("unknwon".to_string()) - .unwrap() - .is_none()); + assert!( + default_scope + .collection("unknwon".to_string()) + .unwrap() + .is_none() + ); assert_eq!( default_scope @@ -349,12 +362,13 @@ fn collection_documents() { .expect("save_document"); assert!(collection_1.get_document("foo").is_ok()); - assert!(db - .default_collection() - .unwrap() - .unwrap() - .get_document("foo") - .is_err()); // Document 1 not in default collection + assert!( + db.default_collection() + .unwrap() + .unwrap() + .get_document("foo") + .is_err() + ); // Document 1 not in default collection // Collection 2 let mut collection_2 = db diff --git a/tests/database_tests.rs b/tests/database_tests.rs index 8753655..955e210 100644 --- a/tests/database_tests.rs +++ b/tests/database_tests.rs @@ -170,9 +170,10 @@ fn db_encryption_key() { { let mut db = Database::open(utils::DB_NAME, Some(cfg_no_encryption.clone())).unwrap(); let mut doc = Document::new_with_id("foo"); - assert!(db - .save_document_with_concurency_control(&mut doc, ConcurrencyControl::LastWriteWins) - .is_ok()); + assert!( + db.save_document_with_concurency_control(&mut doc, ConcurrencyControl::LastWriteWins) + .is_ok() + ); } // Assert database can only be opened with no ecryption & doc can be retrieved, then add encryption diff --git a/tests/query_tests.rs b/tests/query_tests.rs index f94a0e7..12426e3 100644 --- a/tests/query_tests.rs +++ b/tests/query_tests.rs @@ -110,12 +110,14 @@ fn get_index() { utils::with_db(|db| { // Default collection let default_collection = db.default_collection().unwrap().unwrap(); - assert!(default_collection - .create_index( - "new_index1", - &ValueIndexConfiguration::new(QueryLanguage::JSON, r#"[[".someField"]]"#), - ) - .unwrap()); + assert!( + default_collection + .create_index( + "new_index1", + &ValueIndexConfiguration::new(QueryLanguage::JSON, r#"[[".someField"]]"#), + ) + .unwrap() + ); let index1 = default_collection.get_index("new_index1").unwrap(); assert_eq!(index1.name(), "new_index1"); @@ -129,12 +131,14 @@ fn get_index() { .create_collection(String::from("coll"), String::from("scop")) .unwrap(); - assert!(new_coll - .create_index( - "new_index2", - &ValueIndexConfiguration::new(QueryLanguage::JSON, r#"[[".someField2"]]"#), - ) - .unwrap()); + assert!( + new_coll + .create_index( + "new_index2", + &ValueIndexConfiguration::new(QueryLanguage::JSON, r#"[[".someField2"]]"#), + ) + .unwrap() + ); let index2 = new_coll.get_index("new_index2").unwrap(); assert_eq!(index2.name(), "new_index2"); @@ -152,12 +156,13 @@ fn get_index_name_from_explain(explain: &str) -> Option { #[test] fn full_index() { utils::with_db(|db| { - assert!(db - .create_index( + assert!( + db.create_index( "new_index", &ValueIndexConfiguration::new(QueryLanguage::JSON, r#"[[".someField"]]"#), ) - .unwrap()); + .unwrap() + ); // Check index creation let value = db.get_index_names().iter().next().unwrap(); @@ -204,15 +209,16 @@ fn full_index() { #[test] fn partial_index() { utils::with_db(|db| { - assert!(db - .create_index( + assert!( + db.create_index( "new_index", &ValueIndexConfiguration::new( QueryLanguage::JSON, r#"{"WHAT": [[".id"]], "WHERE": ["=", [".someField"], "someValue"]}"# ), ) - .unwrap()); + .unwrap() + ); // Check index creation let value = db.get_index_names().iter().next().unwrap(); @@ -310,9 +316,11 @@ fn array_index() { let index_configuration = ArrayIndexConfiguration::new(QueryLanguage::N1QL, "contacts[].phones", "type").unwrap(); - assert!(default_collection - .create_array_index("two_levels", &index_configuration,) - .unwrap()); + assert!( + default_collection + .create_array_index("two_levels", &index_configuration,) + .unwrap() + ); let query = Query::new( db, diff --git a/tests/replicator_tests.rs b/tests/replicator_tests.rs index 1d64c54..6e922d7 100644 --- a/tests/replicator_tests.rs +++ b/tests/replicator_tests.rs @@ -378,9 +378,11 @@ fn conflict_resolver_save_keep_local() { // Modify 'foo' in DB1 from outdated document foo.mutable_properties().at("i").put_i64(i1); - assert!(local_db - .save_document_resolving(&mut foo, move |_, _| true) - .is_ok()); + assert!( + local_db + .save_document_resolving(&mut foo, move |_, _| true) + .is_ok() + ); // Assert conflict was resolved by keeping latest version assert!(utils::check_callback_with_wait( @@ -460,9 +462,11 @@ fn conflict_resolver_save_keep_remote() { // Modify 'foo' in DB1 from outdated document foo.mutable_properties().at("i").put_i64(i1); - assert!(local_db - .save_document_resolving(&mut foo, move |_, _| false) - .is_err()); + assert!( + local_db + .save_document_resolving(&mut foo, move |_, _| false) + .is_err() + ); // Assert conflict was resolved by keeping central's version assert!(utils::check_callback_with_wait(