Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
rust-rocksdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangzongwu
rust-rocksdb
Commits
41468f31
Commit
41468f31
authored
Sep 30, 2016
by
Jay
Committed by
GitHub
Sep 30, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ffi_try to simplify error handle (#46)
parent
a09bd206
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
3 deletions
+42
-3
lib.rs
librocksdb_sys/src/lib.rs
+16
-2
lib.rs
src/lib.rs
+1
-0
rocksdb.rs
src/rocksdb.rs
+0
-0
rocksdb_options.rs
src/rocksdb_options.rs
+25
-1
No files found.
librocksdb_sys/src/lib.rs
View file @
41468f31
...
...
@@ -86,6 +86,19 @@ pub fn error_message(ptr: *mut c_char) -> String {
s
}
#[macro_export]
macro_rules!
ffi_try
{
(
$func:ident
(
$
(
$arg:expr
),
*
))
=>
({
use
std
::
ptr
;
let
mut
err
=
ptr
::
null_mut
();
let
res
=
$crate
::
$func
(
$
(
$arg
),
*
,
&
mut
err
);
if
!
err
.is_null
()
{
return
Err
(
$crate
::
error_message
(
err
));
}
res
})
}
// TODO audit the use of boolean arguments, b/c I think they need to be u8
// instead...
#[link(name
=
"rocksdb"
)]
...
...
@@ -482,7 +495,8 @@ extern "C" {
mod
test
{
use
super
::
*
;
use
std
::
ffi
::{
CStr
,
CString
};
use
libc
::{
self
,
c_void
,
c_char
};
use
std
::
ptr
;
use
libc
::{
self
,
c_void
};
use
tempdir
::
TempDir
;
#[test]
...
...
@@ -501,7 +515,7 @@ mod test {
.unwrap
();
let
cpath_ptr
=
cpath
.as_ptr
();
let
mut
err
=
0
as
*
mut
c_char
;
let
mut
err
=
ptr
::
null_mut
()
;
let
db
=
rocksdb_open
(
opts
,
cpath_ptr
,
&
mut
err
);
assert
!
(
err
.is_null
(),
error_message
(
err
));
...
...
src/lib.rs
View file @
41468f31
...
...
@@ -17,6 +17,7 @@ extern crate libc;
#[cfg(test)]
extern
crate
tempdir
;
#[macro_use]
pub
extern
crate
librocksdb_sys
;
pub
mod
rocksdb
;
...
...
src/rocksdb.rs
View file @
41468f31
This diff is collapsed.
Click to expand it.
src/rocksdb_options.rs
View file @
41468f31
...
...
@@ -23,7 +23,7 @@ use merge_operator::MergeFn;
use
rocksdb_ffi
::{
self
,
DBOptions
,
DBWriteOptions
,
DBBlockBasedTableOptions
,
DBReadOptions
,
DBCompressionType
,
DBRecoveryMode
,
DBSnapshot
,
DBInstance
};
DBSnapshot
,
DBInstance
,
DBFlushOptions
};
use
std
::
ffi
::
CString
;
use
std
::
mem
;
...
...
@@ -565,6 +565,30 @@ impl Options {
}
}
pub
struct
FlushOptions
{
pub
inner
:
*
mut
DBFlushOptions
,
}
impl
FlushOptions
{
pub
fn
new
()
->
FlushOptions
{
unsafe
{
FlushOptions
{
inner
:
rocksdb_ffi
::
rocksdb_flushoptions_create
(),
}
}
}
pub
fn
set_wait
(
&
mut
self
,
wait
:
bool
)
{
unsafe
{
rocksdb_ffi
::
rocksdb_flushoptions_set_wait
(
self
.inner
,
wait
);}
}
}
impl
Drop
for
FlushOptions
{
fn
drop
(
&
mut
self
)
{
unsafe
{
rocksdb_ffi
::
rocksdb_flushoptions_destroy
(
self
.inner
);}
}
}
#[cfg(test)]
mod
tests
{
use
super
::
Options
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment