From 15ac361762799cd8585ba4b5bb1f104ec1adb1ae Mon Sep 17 00:00:00 2001 From: Dan Burkert Date: Mon, 19 Jan 2015 22:34:26 -0800 Subject: [PATCH] Update for rustc 1.0.0-nightly (ed530d7a3 2015-01-16 22:41:16 +0000) --- src/cursor.rs | 22 +++++++++---------- src/database.rs | 3 +++ src/environment.rs | 6 +++--- src/lib.rs | 2 +- src/transaction.rs | 53 ++++++++++++---------------------------------- 5 files changed, 31 insertions(+), 55 deletions(-) diff --git a/src/cursor.rs b/src/cursor.rs index 8899d3f..4cf10e8 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -102,9 +102,7 @@ impl<'txn, T> CursorExt<'txn> for T where T: Cursor<'txn> {} /// A read-only cursor for navigating the items within a database. pub struct RoCursor<'txn> { cursor: *mut ffi::MDB_cursor, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime<'txn>, + _marker: marker::ContravariantLifetime<'txn>, } impl <'txn> Cursor<'txn> for RoCursor<'txn> { @@ -113,6 +111,9 @@ impl <'txn> Cursor<'txn> for RoCursor<'txn> { } } +impl <'txn> !Sync for RoCursor<'txn> {} +impl <'txn> !Send for RoCursor<'txn> {} + #[unsafe_destructor] impl <'txn> Drop for RoCursor<'txn> { fn drop(&mut self) { @@ -130,9 +131,7 @@ impl <'txn> RoCursor<'txn> { unsafe { try!(lmdb_result(ffi::mdb_cursor_open(txn.txn(), db.dbi(), &mut cursor))); } Ok(RoCursor { cursor: cursor, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime::<'txn>, + _marker: marker::ContravariantLifetime::<'txn>, }) } } @@ -140,9 +139,7 @@ impl <'txn> RoCursor<'txn> { /// A read-only cursor for navigating items within a database. pub struct RwCursor<'txn> { cursor: *mut ffi::MDB_cursor, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime<'txn>, + _marker: marker::ContravariantLifetime<'txn>, } impl <'txn> Cursor<'txn> for RwCursor<'txn> { @@ -151,6 +148,9 @@ impl <'txn> Cursor<'txn> for RwCursor<'txn> { } } +impl <'txn> !Sync for RwCursor<'txn> {} +impl <'txn> !Send for RwCursor<'txn> {} + #[unsafe_destructor] impl <'txn> Drop for RwCursor<'txn> { fn drop(&mut self) { @@ -168,9 +168,7 @@ impl <'txn> RwCursor<'txn> { unsafe { try!(lmdb_result(ffi::mdb_cursor_open(txn.txn(), db.dbi(), &mut cursor))); } Ok(RwCursor { cursor: cursor, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime::<'txn>, + _marker: marker::ContravariantLifetime::<'txn>, }) } diff --git a/src/database.rs b/src/database.rs index c2371e1..e54c615 100644 --- a/src/database.rs +++ b/src/database.rs @@ -40,3 +40,6 @@ impl Database { self.dbi } } + +unsafe impl Sync for Database {} +unsafe impl Send for Database {} diff --git a/src/environment.rs b/src/environment.rs index 6f20cb9..126055a 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -20,9 +20,6 @@ pub struct Environment { dbi_open_mutex: Mutex<()>, } -unsafe impl Send for Environment {} -unsafe impl Sync for Environment {} - impl Environment { /// Creates a new builder for specifying options for opening an LMDB environment. @@ -139,6 +136,9 @@ impl Environment { } } +unsafe impl Send for Environment {} +unsafe impl Sync for Environment {} + impl Drop for Environment { fn drop(&mut self) { unsafe { ffi::mdb_env_close(self.env) } diff --git a/src/lib.rs b/src/lib.rs index f10c6f0..f00bece 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ //! Provides the minimal amount of abstraction necessary to interact with LMDB safely in Rust. In //! general, the API is very similar to the LMDB [C-API](http://symas.com/mdb/doc/). -#![feature(unsafe_destructor)] +#![feature(unsafe_destructor, optin_builtin_traits)] #![allow(unstable)] #[macro_use] extern crate log; diff --git a/src/transaction.rs b/src/transaction.rs index 092549f..8fee272 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -108,11 +108,12 @@ impl<'env, T> TransactionExt<'env> for T where T: Transaction<'env> {} /// An LMDB read-only transaction. pub struct RoTransaction<'env> { txn: *mut ffi::MDB_txn, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime<'env>, + _marker: marker::ContravariantLifetime<'env>, } +impl <'env> !Sync for RoTransaction<'env> {} +impl <'env> !Send for RoTransaction<'env> {} + #[unsafe_destructor] impl <'env> Drop for RoTransaction<'env> { fn drop(&mut self) { @@ -132,12 +133,7 @@ impl <'env> RoTransaction<'env> { ptr::null_mut(), ffi::MDB_RDONLY, &mut txn))); - Ok(RoTransaction { - txn: txn, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime::<'env>, - }) + Ok(RoTransaction { txn: txn, _marker: marker::ContravariantLifetime::<'env> }) } } @@ -157,12 +153,7 @@ impl <'env> RoTransaction<'env> { mem::forget(self); ffi::mdb_txn_reset(txn) }; - InactiveTransaction { - txn: txn, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime::<'env>, - } + InactiveTransaction { txn: txn, _marker: marker::ContravariantLifetime::<'env> } } } @@ -175,9 +166,7 @@ impl <'env> Transaction<'env> for RoTransaction<'env> { /// An inactive read-only transaction. pub struct InactiveTransaction<'env> { txn: *mut ffi::MDB_txn, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime<'env>, + _marker: marker::ContravariantLifetime<'env>, } #[unsafe_destructor] @@ -199,23 +188,19 @@ impl <'env> InactiveTransaction<'env> { mem::forget(self); try!(lmdb_result(ffi::mdb_txn_renew(txn))) }; - Ok(RoTransaction { - txn: txn, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime::<'env>, - }) + Ok(RoTransaction { txn: txn, _marker: marker::ContravariantLifetime::<'env> }) } } /// An LMDB read-write transaction. pub struct RwTransaction<'env> { txn: *mut ffi::MDB_txn, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime<'env>, + _marker: marker::ContravariantLifetime<'env>, } +impl <'env> !Sync for RwTransaction<'env> {} +impl <'env> !Send for RwTransaction<'env> {} + #[unsafe_destructor] impl <'env> Drop for RwTransaction<'env> { fn drop(&mut self) { @@ -235,12 +220,7 @@ impl <'env> RwTransaction<'env> { ptr::null_mut(), EnvironmentFlags::empty().bits(), &mut txn))); - Ok(RwTransaction { - txn: txn, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime::<'env>, - }) + Ok(RwTransaction { txn: txn, _marker: marker::ContravariantLifetime::<'env> }) } } @@ -372,12 +352,7 @@ impl <'env> RwTransaction<'env> { let env: *mut ffi::MDB_env = ffi::mdb_txn_env(self.txn()); ffi::mdb_txn_begin(env, self.txn(), 0, &mut nested); } - Ok(RwTransaction { - txn: nested, - _no_sync: marker::NoSync, - _no_send: marker::NoSend, - _contravariant: marker::ContravariantLifetime::<'env>, - }) + Ok(RwTransaction { txn: nested, _marker: marker::ContravariantLifetime::<'env> }) } }