Add Collection.get_name()

pull/2/head
Thijs Cadier 9 years ago
parent f18fde5c77
commit b1987b1e36

@ -132,7 +132,8 @@ mod tests {
for _ in 0..10 {
let client = pool.pop();
pool.pop();
client.get_collection("rust_test", "items");
let collection = client.get_collection("rust_test", "items");
assert_eq!("items", collection.get_name().to_mut());
}
}

@ -1,4 +1,6 @@
use std::ptr;
use std::ffi::CStr;
use std::borrow::Cow;
use mongo_c_driver_wrapper::bindings;
@ -158,6 +160,13 @@ impl<'a> Collection<'a> {
)
}
pub fn get_name(&self) -> Cow<str> {
let cstr = unsafe {
CStr::from_ptr(bindings::mongoc_collection_get_name(self.inner))
};
String::from_utf8_lossy(cstr.to_bytes())
}
pub fn insert_with_options(
&'a self,
insert_flags: &Flags<InsertFlag>,
@ -288,6 +297,8 @@ mod tests {
let mut collection = client.get_collection("rust_driver_test", "items");
collection.drop().unwrap_or(());
assert_eq!("items", collection.get_name().to_mut());
let mut document = bson::Document::new();
document.insert("key_1".to_string(), bson::Bson::String("Value 1".to_string()));
document.insert("key_2".to_string(), bson::Bson::String("Value 2".to_string()));

Loading…
Cancel
Save