Change write concern new to default and document it

pull/13/head
Thijs Cadier 9 years ago
parent b6da5c9e43
commit 282add350a

@ -55,7 +55,7 @@ impl BulkOperationOptions {
pub fn default() -> BulkOperationOptions {
BulkOperationOptions {
ordered: false,
write_concern: WriteConcern::new()
write_concern: WriteConcern::default()
}
}
}
@ -138,7 +138,7 @@ impl InsertOptions {
pub fn default() -> InsertOptions {
InsertOptions {
insert_flags: Flags::new(),
write_concern: WriteConcern::new()
write_concern: WriteConcern::default()
}
}
}
@ -156,7 +156,7 @@ impl RemoveOptions {
pub fn default() -> RemoveOptions {
RemoveOptions {
remove_flags: Flags::new(),
write_concern: WriteConcern::new()
write_concern: WriteConcern::default()
}
}
}
@ -174,7 +174,7 @@ impl UpdateOptions {
pub fn default() -> UpdateOptions {
UpdateOptions {
update_flags: Flags::new(),
write_concern: WriteConcern::new()
write_concern: WriteConcern::default()
}
}
}
@ -573,7 +573,7 @@ impl<'a> Collection<'a> {
) -> Result<()> {
assert!(!self.inner.is_null());
let default_write_concern = WriteConcern::new();
let default_write_concern = WriteConcern::default();
let write_concern = write_concern.unwrap_or(&default_write_concern);
let mut error = BsoncError::empty();

@ -1,16 +1,44 @@
//! Abstraction on top of the MongoDB connection write concern.
use mongoc::bindings;
/// Possible write concern levels, only default is supported at the moment.
pub enum WriteConcernLevel {
/// By default, writes block awaiting acknowledgment from MongoDB. Acknowledged write concern allows clients to catch network, duplicate key, and other errors.
Default,
// We'd like to support the following write concerns too at some point, pull request welcome:
// With this write concern, MongoDB does not acknowledge the receipt of write operation. Unacknowledged is similar to errors ignored; however, mongoc attempts to receive and handle network errors when possible.
// WriteUnacknowledged,
// Block until a write has been propagated to a majority of the nodes in the replica set.
// Majority,
// Block until a write has been propagated to at least n nodes in the replica set.
// AtLeastNumberOfNodes(u32),
// Block until the node receiving the write has committed the journal.
// Journal
}
/// This tells the driver what level of acknowledgment to await from the server.
/// The default, `Default`, is right for the great majority of applications.
pub struct WriteConcern {
inner: *mut bindings::mongoc_write_concern_t
}
impl WriteConcern {
pub fn new() -> WriteConcern {
/// Get the default write concern
pub fn default() -> WriteConcern {
Self::new(WriteConcernLevel::Default)
}
/// Create a new write concern
pub fn new(_: WriteConcernLevel) -> WriteConcern {
let inner = unsafe { bindings::mongoc_write_concern_new() };
assert!(!inner.is_null());
WriteConcern { inner: inner }
}
#[doc(hidden)]
pub fn inner(&self) -> *const bindings::mongoc_write_concern_t {
assert!(!self.inner.is_null());
self.inner

@ -1,7 +1,7 @@
use mongo_driver::write_concern::WriteConcern;
#[test]
fn test_write_concern() {
let write_concern = WriteConcern::new();
fn test_default_write_concern() {
let write_concern = WriteConcern::default();
assert!(!write_concern.inner().is_null());
}

Loading…
Cancel
Save