Fix warnings on latest stable

pull/57/head
Thijs Cadier 4 years ago
parent ebe89683b4
commit 97d22cc241

@ -102,7 +102,7 @@ pub mod bindings {
pub fn mongoc_database_get_collection(database: *mut mongoc_database_t, name: *const ::libc::c_char) -> *mut mongoc_collection_t;
pub fn mongoc_database_get_name(database: *mut mongoc_database_t) -> *const ::libc::c_char;
pub fn mongoc_database_destroy(database: *mut mongoc_database_t) -> ();
pub fn mongoc_database_has_collection(database: *mut mongoc_database_t, name: *const ::libc::c_char, error: *mut bson_error_t) -> ::libc::int32_t;
pub fn mongoc_database_has_collection(database: *mut mongoc_database_t, name: *const ::libc::c_char, error: *mut bson_error_t) -> i32;
}
// Client

@ -25,7 +25,7 @@ impl Bsonc {
pub fn from_document(document: &bson::Document) -> Result<Bsonc> {
let mut buffer = Vec::new();
try!(bson::encode_document(&mut buffer, document));
bson::encode_document(&mut buffer, document)?;
let inner = unsafe {
bindings::bson_new_from_data(
@ -60,8 +60,7 @@ impl Bsonc {
slice::from_raw_parts(data_ptr, data_len)
};
let document = try!(bson::decode_document(&mut slice));
Ok(document)
Ok(bson::decode_document(&mut slice)?)
}
/// Decode a bson from the C side to a document with lossy UTF-8 decoding
@ -82,8 +81,7 @@ impl Bsonc {
slice::from_raw_parts(data_ptr, data_len)
};
let document = try!(bson::decode_document_utf8_lossy(&mut slice));
Ok(document)
Ok(bson::decode_document_utf8_lossy(&mut slice)?)
}
pub fn as_json(&self) -> String {

@ -142,11 +142,11 @@ impl SslOptions {
crl_file: Option<PathBuf>,
weak_cert_validation: bool
) -> io::Result<SslOptions> {
let pem_file_cstring = try!(Self::cstring_from_path(&pem_file));
let pem_file_cstring = Self::cstring_from_path(&pem_file)?;
let pem_password_cstring = Self::cstring_from_string(&pem_password);
let ca_file_cstring = try!(Self::cstring_from_path(&ca_file));
let ca_dir_cstring = try!(Self::cstring_from_path(&ca_dir));
let crl_file_cstring = try!(Self::cstring_from_path(&crl_file));
let ca_file_cstring = Self::cstring_from_path(&ca_file)?;
let ca_dir_cstring = Self::cstring_from_path(&ca_dir)?;
let crl_file_cstring = Self::cstring_from_path(&crl_file)?;
let ssl_options = bindings::mongoc_ssl_opt_t {
pem_file: match pem_file_cstring {
@ -192,7 +192,7 @@ impl SslOptions {
fn cstring_from_path(path: &Option<PathBuf>) -> io::Result<Option<CString>> {
match path {
&Some(ref p) => {
try!(File::open(p.as_path()));
File::open(p.as_path())?;
Ok(Some(CString::new(p.to_string_lossy().into_owned()).unwrap()))
},
&None => Ok(None)

@ -247,10 +247,10 @@ impl<'a> Collection<'a> {
bindings::mongoc_collection_aggregate(
self.inner,
options.query_flags.flags(),
try!(Bsonc::from_document(pipeline)).inner(),
Bsonc::from_document(pipeline)?.inner(),
match options.options {
Some(ref o) => {
try!(Bsonc::from_document(o)).inner()
Bsonc::from_document(o)?.inner()
},
None => ptr::null()
},
@ -292,7 +292,7 @@ impl<'a> Collection<'a> {
options.skip,
options.limit,
options.batch_size,
try!(Bsonc::from_document(&command)).inner(),
Bsonc::from_document(&command)?.inner(),
match fields_bsonc {
Some(ref f) => f.inner(),
None => ptr::null()
@ -331,7 +331,7 @@ impl<'a> Collection<'a> {
let success = unsafe {
bindings::mongoc_collection_command_simple(
self.inner,
try!(Bsonc::from_document(&command)).inner(),
Bsonc::from_document(&command)?.inner(),
match read_prefs {
Some(ref prefs) => prefs.inner(),
None => ptr::null()
@ -365,7 +365,7 @@ impl<'a> Collection<'a> {
let default_options = CountOptions::default();
let options = options.unwrap_or(&default_options);
let opts_bsonc = match options.opts {
Some(ref o) => Some(try!(Bsonc::from_document(o))),
Some(ref o) => Some(Bsonc::from_document(o)?),
None => None
};
@ -374,7 +374,7 @@ impl<'a> Collection<'a> {
bindings::mongoc_collection_count_with_opts(
self.inner,
options.query_flags.flags(),
try!(Bsonc::from_document(query)).inner(),
Bsonc::from_document(query)?.inner(),
options.skip as i64,
options.limit as i64,
match opts_bsonc {
@ -458,7 +458,7 @@ impl<'a> Collection<'a> {
options.skip,
options.limit,
options.batch_size,
try!(Bsonc::from_document(query)).inner(),
Bsonc::from_document(query)?.inner(),
match fields_bsonc {
Some(ref f) => f.inner(),
None => ptr::null()
@ -505,13 +505,13 @@ impl<'a> Collection<'a> {
// them around long enough.
let sort_bsonc = match options.sort {
Some(ref doc) => {
Some(try!(Bsonc::from_document(doc)))
Some(Bsonc::from_document(doc)?)
},
None => None
};
let update_bsonc = match operation {
FindAndModifyOperation::Update(ref doc) | FindAndModifyOperation::Upsert(ref doc) => {
Some(try!(Bsonc::from_document(doc)))
Some(Bsonc::from_document(doc)?)
},
FindAndModifyOperation::Remove => None
};
@ -519,7 +519,7 @@ impl<'a> Collection<'a> {
let success = unsafe {
bindings::mongoc_collection_find_and_modify(
self.inner,
try!(Bsonc::from_document(&query)).inner(),
Bsonc::from_document(&query)?.inner(),
match sort_bsonc {
Some(ref s) => s.inner(),
None => ptr::null()
@ -582,7 +582,7 @@ impl<'a> Collection<'a> {
bindings::mongoc_collection_insert(
self.inner,
options.insert_flags.flags(),
try!(Bsonc::from_document(&document)).inner(),
Bsonc::from_document(&document)?.inner(),
options.write_concern.inner(),
error.mut_inner()
)
@ -613,7 +613,7 @@ impl<'a> Collection<'a> {
bindings::mongoc_collection_remove(
self.inner,
options.remove_flags.flags(),
try!(Bsonc::from_document(&selector)).inner(),
Bsonc::from_document(&selector)?.inner(),
options.write_concern.inner(),
error.mut_inner()
)
@ -642,7 +642,7 @@ impl<'a> Collection<'a> {
let success = unsafe {
bindings::mongoc_collection_save(
self.inner,
try!(Bsonc::from_document(&document)).inner(),
Bsonc::from_document(&document)?.inner(),
write_concern.inner(),
error.mut_inner()
)
@ -673,8 +673,8 @@ impl<'a> Collection<'a> {
bindings::mongoc_collection_update(
self.inner,
options.update_flags.flags(),
try!(Bsonc::from_document(&selector)).inner(),
try!(Bsonc::from_document(&update)).inner(),
Bsonc::from_document(&selector)?.inner(),
Bsonc::from_document(&update)?.inner(),
options.write_concern.inner(),
error.mut_inner()
)
@ -757,7 +757,7 @@ impl<'a>BulkOperation<'a> {
unsafe {
bindings::mongoc_bulk_operation_insert(
self.inner,
try!(Bsonc::from_document(&document)).inner()
Bsonc::from_document(&document)?.inner()
)
}
Ok(())
@ -773,7 +773,7 @@ impl<'a>BulkOperation<'a> {
unsafe {
bindings::mongoc_bulk_operation_remove(
self.inner,
try!(Bsonc::from_document(&selector)).inner()
Bsonc::from_document(&selector)?.inner()
)
}
Ok(())
@ -789,7 +789,7 @@ impl<'a>BulkOperation<'a> {
unsafe {
bindings::mongoc_bulk_operation_remove_one(
self.inner,
try!(Bsonc::from_document(&selector)).inner()
Bsonc::from_document(&selector)?.inner()
)
}
Ok(())
@ -807,8 +807,8 @@ impl<'a>BulkOperation<'a> {
unsafe {
bindings::mongoc_bulk_operation_replace_one(
self.inner,
try!(Bsonc::from_document(&selector)).inner(),
try!(Bsonc::from_document(&document)).inner(),
Bsonc::from_document(&selector)?.inner(),
Bsonc::from_document(&document)?.inner(),
upsert as u8
)
}
@ -830,8 +830,8 @@ impl<'a>BulkOperation<'a> {
unsafe {
bindings::mongoc_bulk_operation_update_one(
self.inner,
try!(Bsonc::from_document(&selector)).inner(),
try!(Bsonc::from_document(&document)).inner(),
Bsonc::from_document(&selector)?.inner(),
Bsonc::from_document(&document)?.inner(),
upsert as u8
)
}
@ -853,8 +853,8 @@ impl<'a>BulkOperation<'a> {
unsafe {
bindings::mongoc_bulk_operation_update(
self.inner,
try!(Bsonc::from_document(&selector)).inner(),
try!(Bsonc::from_document(&document)).inner(),
Bsonc::from_document(&selector)?.inner(),
Bsonc::from_document(&document)?.inner(),
upsert as u8
)
}

@ -79,7 +79,7 @@ impl<'a> Database<'a> {
options.skip,
options.limit,
options.batch_size,
try!(Bsonc::from_document(&command)).inner(),
Bsonc::from_document(&command)?.inner(),
match fields_bsonc {
Some(ref f) => f.inner(),
None => ptr::null()
@ -135,7 +135,7 @@ impl<'a> Database<'a> {
let success = unsafe {
bindings::mongoc_database_command_simple(
self.inner,
try!(Bsonc::from_document(&command)).inner(),
Bsonc::from_document(&command)?.inner(),
match read_prefs {
Some(ref prefs) => prefs.inner(),
None => ptr::null()
@ -166,7 +166,7 @@ impl<'a> Database<'a> {
let mut error = BsoncError::empty();
let name_cstring = CString::new(name).unwrap();
let options_bsonc = match options {
Some(o) => Some(try!(Bsonc::from_document(o))),
Some(o) => Some(Bsonc::from_document(o)?),
None => None
};
@ -263,4 +263,4 @@ fn test_get_coll_name_from_doc() {
assert_eq!("cursor_items", get_coll_name_from_doc(&command).unwrap());
let command = doc! {"error": "cursor_items"};
assert!(get_coll_name_from_doc(&command).is_err());
}
}

@ -51,18 +51,7 @@ impl fmt::Debug for MongoError {
}
impl error::Error for MongoError {
fn description(&self) -> &str {
match *self {
MongoError::Bsonc(ref err) => err.description(),
MongoError::Decoder(ref err) => err.description(),
MongoError::Encoder(ref err) => err.description(),
MongoError::ValueAccessError(ref err) => err.description(),
MongoError::InvalidParams(ref err) => err.description(),
MongoError::Nul(ref err) => err.description()
}
}
fn cause(&self) -> Option<&error::Error> {
fn cause(&self) -> Option<&dyn error::Error> {
match *self {
MongoError::Bsonc(ref err) => Some(err),
MongoError::Decoder(ref err) => Some(err),

@ -38,7 +38,7 @@ extern crate serde;
use std::ffi::CStr;
use std::ptr;
use std::result;
use std::sync::{Once,ONCE_INIT};
use std::sync::Once;
use mongoc::bindings;
@ -61,7 +61,7 @@ pub type Result<T> = result::Result<T, MongoError>;
/// Result that's used in bulk operations.
pub type BulkOperationResult<T> = result::Result<T, BulkOperationError>;
static MONGOC_INIT: Once = ONCE_INIT;
static MONGOC_INIT: Once = Once::new();
/// Init mongo driver, needs to be called once before doing
/// anything else.

Loading…
Cancel
Save