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
e3b7fbd0
Commit
e3b7fbd0
authored
Nov 17, 2014
by
Tyler Neely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small cleanup
parent
954909a8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
+20
-10
lib.rs
src/lib.rs
+20
-10
No files found.
src/lib.rs
View file @
e3b7fbd0
extern
crate
libc
;
use
libc
::{
c_int
,
size_t
};
use
std
::
io
::{
IoResult
,
IoError
};
use
libc
::{
c_int
,
c_void
,
size_t
};
use
std
::
io
::{
IoResult
,
IoError
,
BufferedStream
};
use
std
::
c_vec
::
CVec
;
#[repr(C)]
struct
RocksdbOptions
(
*
const
c_
int
);
struct
RocksdbOptions
(
*
const
c_
void
);
#[repr(C)]
struct
RocksdbInstance
(
*
const
c_
int
);
struct
RocksdbInstance
(
*
const
c_
void
);
#[repr(C)]
struct
RocksdbWriteOptions
(
*
const
c_
int
);
struct
RocksdbWriteOptions
(
*
const
c_
void
);
#[repr(C)]
struct
RocksdbReadOptions
(
*
const
c_
int
);
struct
RocksdbReadOptions
(
*
const
c_
void
);
#[link(name
=
"rocksdb"
)]
extern
{
...
...
@@ -62,8 +62,10 @@ impl Rocksdb {
let
db
=
rocksdb_open
(
opts
,
cpath_ptr
,
err
);
let
RocksdbInstance
(
db_ptr
)
=
db
;
if
err
.is_not_null
()
{
libc
::
free
(
err
as
*
mut
c_void
);
return
Err
(
IoError
::
last_error
());
}
libc
::
free
(
err
as
*
mut
c_void
);
if
db_ptr
.is_null
()
{
return
Err
(
IoError
::
last_error
());
}
...
...
@@ -79,8 +81,10 @@ impl Rocksdb {
key
.len
()
as
size_t
,
value
.as_ptr
(),
value
.len
()
as
size_t
,
err
);
if
err
.is_not_null
()
{
libc
::
free
(
err
as
*
mut
c_void
);
return
Err
(
IoError
::
last_error
());
}
libc
::
free
(
err
as
*
mut
c_void
);
return
Ok
(
true
)
}
}
...
...
@@ -93,17 +97,19 @@ impl Rocksdb {
return
Err
(
IoError
::
last_error
());
}
let
mut
val_len
:
size_t
=
0
;
let
val_len
:
size_t
=
0
;
let
val_len_ptr
=
&
val_len
as
*
const
size_t
;
let
err
=
0
as
*
mut
i8
;
let
val
=
rocksdb_get
(
self
.inner
,
readopts
,
key
.as_ptr
(),
key
.len
()
as
size_t
,
val_len_ptr
,
err
);
if
err
.is_not_null
()
{
libc
::
free
(
err
as
*
mut
c_void
);
return
Err
(
IoError
::
last_error
());
}
libc
::
free
(
err
as
*
mut
c_void
);
return
Ok
(
CVec
::
new_with_dtor
(
val
,
val_len
as
uint
,
proc
(){
libc
::
free
(
val
as
*
mut
libc
::
c_void
);
libc
::
free
(
val
as
*
mut
c_void
);
}))
}
}
...
...
@@ -119,9 +125,9 @@ fn external() {
let
db
=
Rocksdb
::
open
(
"testdb"
,
true
)
.unwrap
();
db
.put
(
b
"k1"
,
b
"v1111"
);
let
r
=
db
.get
(
b
"k1"
)
.unwrap
();
db
.close
();
let
v
=
r
.get
(
0
)
.unwrap
();
assert
!
(
r
.len
()
==
5
);
let
v
=
r
.get
(
0
)
.unwrap
();
db
.close
();
}
#[test]
...
...
@@ -143,6 +149,7 @@ fn internal() {
let
err
=
0
as
*
mut
i8
;
let
db
=
rocksdb_open
(
opts
,
cpath_ptr
,
err
);
assert
!
(
err
.is_null
());
libc
::
free
(
err
as
*
mut
c_void
);
let
writeopts
=
rocksdb_writeoptions_create
();
let
RocksdbWriteOptions
(
write_opt_ptr
)
=
writeopts
;
...
...
@@ -153,15 +160,18 @@ fn internal() {
rocksdb_put
(
db
,
writeopts
,
key
.as_ptr
(),
4
,
val
.as_ptr
(),
8
,
err
);
assert
!
(
err
.is_null
());
libc
::
free
(
err
as
*
mut
c_void
);
let
readopts
=
rocksdb_readoptions_create
();
let
RocksdbReadOptions
(
read_opts_ptr
)
=
readopts
;
assert
!
(
read_opts_ptr
.is_not_null
());
libc
::
free
(
err
as
*
mut
c_void
);
let
mut
val_len
:
size_t
=
0
;
let
val_len_ptr
=
&
val_len
as
*
const
size_t
;
rocksdb_get
(
db
,
readopts
,
key
.as_ptr
(),
4
,
val_len_ptr
,
err
);
assert
!
(
err
.is_null
());
libc
::
free
(
err
as
*
mut
c_void
);
rocksdb_close
(
db
);
}
}
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