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
beb98146
Commit
beb98146
authored
Feb 23, 2015
by
Tyler Neely
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4 from mcobzarenco/master
Updated to compile with rustc 1.0.0.alpha.2
parents
dfbf55f8
9e33a8dc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
25 deletions
+29
-25
lib.rs
src/lib.rs
+7
-1
main.rs
src/main.rs
+2
-1
merge_operator.rs
src/merge_operator.rs
+4
-4
rocksdb.rs
src/rocksdb.rs
+16
-19
No files found.
src/lib.rs
View file @
beb98146
...
@@ -15,7 +15,13 @@
...
@@ -15,7 +15,13 @@
*/
*/
#
!
[
crate_id
=
"rocksdb"
]
#
!
[
crate_id
=
"rocksdb"
]
#
!
[
crate_type
=
"lib"
]
#
!
[
crate_type
=
"lib"
]
#
!
[
allow
(
dead_code
)]
#
!
[
feature
(
collections
)]
#
!
[
feature
(
core
)]
#
!
[
feature
(
fs
)]
#
!
[
feature
(
io
)]
#
!
[
feature
(
libc
)]
#
!
[
feature
(
path
)]
#
!
[
feature
(
std_misc
)]
pub
use
ffi
as
rocksdb_ffi
;
pub
use
ffi
as
rocksdb_ffi
;
pub
use
ffi
::{
pub
use
ffi
::{
...
...
src/main.rs
View file @
beb98146
...
@@ -13,7 +13,8 @@
...
@@ -13,7 +13,8 @@
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
#
!
[
allow
(
unstable
)]
#
!
[
feature
(
collections
)]
#
!
[
feature
(
test
)]
extern
crate
rocksdb
;
extern
crate
rocksdb
;
extern
crate
test
;
extern
crate
test
;
...
...
src/merge_operator.rs
View file @
beb98146
...
@@ -101,17 +101,17 @@ pub extern "C" fn partial_merge_callback(
...
@@ -101,17 +101,17 @@ pub extern "C" fn partial_merge_callback(
}
}
pub
struct
MergeOperands
<
'a
>
{
pub
struct
MergeOperands
{
operands_list
:
*
const
*
const
c_char
,
operands_list
:
*
const
*
const
c_char
,
operands_list_len
:
*
const
size_t
,
operands_list_len
:
*
const
size_t
,
num_operands
:
usize
,
num_operands
:
usize
,
cursor
:
usize
,
cursor
:
usize
,
}
}
impl
<
'a
>
MergeOperands
<
'a
>
{
impl
MergeOperands
{
fn
new
(
operands_list
:
*
const
*
const
c_char
,
fn
new
(
operands_list
:
*
const
*
const
c_char
,
operands_list_len
:
*
const
size_t
,
operands_list_len
:
*
const
size_t
,
num_operands
:
c_int
)
->
MergeOperands
<
'a
>
{
num_operands
:
c_int
)
->
MergeOperands
{
assert
!
(
num_operands
>=
0
);
assert
!
(
num_operands
>=
0
);
MergeOperands
{
MergeOperands
{
operands_list
:
operands_list
,
operands_list
:
operands_list
,
...
@@ -122,7 +122,7 @@ impl <'a> MergeOperands<'a> {
...
@@ -122,7 +122,7 @@ impl <'a> MergeOperands<'a> {
}
}
}
}
impl
<
'a
>
Iterator
for
&
'a
mut
MergeOperands
<
'a
>
{
impl
<
'a
>
Iterator
for
&
'a
mut
MergeOperands
{
type
Item
=
&
'a
[
u8
];
type
Item
=
&
'a
[
u8
];
fn
next
(
&
mut
self
)
->
Option
<&
'a
[
u8
]
>
{
fn
next
(
&
mut
self
)
->
Option
<&
'a
[
u8
]
>
{
use
std
::
raw
::
Slice
;
use
std
::
raw
::
Slice
;
...
...
src/rocksdb.rs
View file @
beb98146
...
@@ -13,19 +13,17 @@
...
@@ -13,19 +13,17 @@
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
#
!
[
allow
(
unstable
)]
extern
crate
libc
;
extern
crate
libc
;
use
self
::
libc
::{
c_void
,
size_t
};
use
self
::
libc
::{
c_void
,
size_t
};
use
std
::
ffi
::
CString
;
use
std
::
fs
::{
self
,
PathExt
};
use
std
::
ops
::
Deref
;
use
std
::
ops
::
Deref
;
use
std
::
path
::
Path
;
use
std
::
ptr
::
Unique
;
use
std
::
ptr
::
Unique
;
use
std
::
ffi
::
CString
;
use
std
::
str
::
from_utf8
;
use
std
::
slice
;
use
std
::
slice
;
use
std
::
str
::
from_c_str
;
use
std
::
str
::
from_c_str
;
use
std
::
io
::
fs
::
PathExtensions
;
use
std
::
str
::
from_utf8
;
use
std
::
io
;
use
std
::
io
::
fs
;
use
rocksdb_ffi
;
use
rocksdb_ffi
;
use
rocksdb_ffi
::
RocksDBSnapshot
;
use
rocksdb_ffi
::
RocksDBSnapshot
;
...
@@ -49,8 +47,8 @@ impl RocksDB {
...
@@ -49,8 +47,8 @@ impl RocksDB {
let
ospath
=
Path
::
new
(
path
);
let
ospath
=
Path
::
new
(
path
);
if
!
ospath
.exists
()
{
if
!
ospath
.exists
()
{
match
fs
::
mkdir_recursive
(
&
ospath
,
io
::
USER_DIR
)
{
match
fs
::
create_dir_all
(
&
ospath
)
{
Err
(
e
)
=>
return
Err
(
e
.desc
),
Err
(
e
)
=>
return
Err
(
""
),
Ok
(
_
)
=>
(),
Ok
(
_
)
=>
(),
}
}
}
}
...
@@ -146,8 +144,7 @@ impl RocksDB {
...
@@ -146,8 +144,7 @@ impl RocksDB {
}
}
}
}
pub
fn
get
<
'a
>
(
&
self
,
key
:
&
[
u8
])
->
pub
fn
get
(
&
self
,
key
:
&
[
u8
])
->
RocksDBResult
<
RocksDBVector
,
&
str
>
{
RocksDBResult
<
'a
,
RocksDBVector
,
&
str
>
{
unsafe
{
unsafe
{
let
readopts
=
rocksdb_ffi
::
rocksdb_readoptions_create
();
let
readopts
=
rocksdb_ffi
::
rocksdb_readoptions_create
();
if
readopts
.
0
.is_null
()
{
if
readopts
.
0
.is_null
()
{
...
@@ -202,14 +199,14 @@ pub struct RocksDBVector {
...
@@ -202,14 +199,14 @@ pub struct RocksDBVector {
impl
Deref
for
RocksDBVector
{
impl
Deref
for
RocksDBVector
{
type
Target
=
[
u8
];
type
Target
=
[
u8
];
fn
deref
(
&
self
)
->
&
[
u8
]
{
fn
deref
(
&
self
)
->
&
[
u8
]
{
unsafe
{
slice
::
from_raw_mut_buf
(
&
self
.base
.
0
,
self
.len
)
}
unsafe
{
slice
::
from_raw_mut_buf
(
self
.base
.deref
()
,
self
.len
)
}
}
}
}
}
impl
Drop
for
RocksDBVector
{
impl
Drop
for
RocksDBVector
{
fn
drop
(
&
mut
self
)
{
fn
drop
(
&
mut
self
)
{
unsafe
{
unsafe
{
libc
::
free
(
self
.base
.
0
as
*
mut
libc
::
c_void
);
libc
::
free
(
*
self
.base
.deref
()
as
*
mut
libc
::
c_void
);
}
}
}
}
}
}
...
@@ -217,7 +214,7 @@ impl Drop for RocksDBVector {
...
@@ -217,7 +214,7 @@ impl Drop for RocksDBVector {
impl
RocksDBVector
{
impl
RocksDBVector
{
pub
fn
from_c
(
val
:
*
mut
u8
,
val_len
:
size_t
)
->
RocksDBVector
{
pub
fn
from_c
(
val
:
*
mut
u8
,
val_len
:
size_t
)
->
RocksDBVector
{
unsafe
{
unsafe
{
let
base
=
Unique
(
val
);
let
base
=
Unique
::
new
(
val
);
RocksDBVector
{
RocksDBVector
{
base
:
base
,
base
:
base
,
len
:
val_len
as
usize
,
len
:
val_len
as
usize
,
...
@@ -232,15 +229,15 @@ impl RocksDBVector {
...
@@ -232,15 +229,15 @@ impl RocksDBVector {
// RocksDBResult exists because of the inherent difference between
// RocksDBResult exists because of the inherent difference between
// an operational failure and the absence of a possible result.
// an operational failure and the absence of a possible result.
#[derive(Clone,
PartialEq,
PartialOrd,
Eq,
Ord,
Show
)]
#[derive(Clone,
PartialEq,
PartialOrd,
Eq,
Ord,
Debug
)]
pub
enum
RocksDBResult
<
'a
,
T
,
E
>
{
pub
enum
RocksDBResult
<
T
,
E
>
{
Some
(
T
),
Some
(
T
),
None
,
None
,
Error
(
E
),
Error
(
E
),
}
}
impl
<
'a
,
T
,
E
>
RocksDBResult
<
'a
,
T
,
E
>
{
impl
<
T
,
E
>
RocksDBResult
<
T
,
E
>
{
pub
fn
map
<
U
,
F
:
FnOnce
(
T
)
->
U
>
(
self
,
f
:
F
)
->
RocksDBResult
<
'a
,
U
,
E
>
{
pub
fn
map
<
U
,
F
:
FnOnce
(
T
)
->
U
>
(
self
,
f
:
F
)
->
RocksDBResult
<
U
,
E
>
{
match
self
{
match
self
{
RocksDBResult
::
Some
(
x
)
=>
RocksDBResult
::
Some
(
f
(
x
)),
RocksDBResult
::
Some
(
x
)
=>
RocksDBResult
::
Some
(
f
(
x
)),
RocksDBResult
::
None
=>
RocksDBResult
::
None
,
RocksDBResult
::
None
=>
RocksDBResult
::
None
,
...
@@ -258,7 +255,7 @@ impl <'a,T,E> RocksDBResult<'a,T,E> {
...
@@ -258,7 +255,7 @@ impl <'a,T,E> RocksDBResult<'a,T,E> {
}
}
}
}
pub
fn
on_error
<
U
,
F
:
FnOnce
(
E
)
->
U
>
(
self
,
f
:
F
)
->
RocksDBResult
<
'a
,
T
,
U
>
{
pub
fn
on_error
<
U
,
F
:
FnOnce
(
E
)
->
U
>
(
self
,
f
:
F
)
->
RocksDBResult
<
T
,
U
>
{
match
self
{
match
self
{
RocksDBResult
::
Some
(
x
)
=>
RocksDBResult
::
Some
(
x
),
RocksDBResult
::
Some
(
x
)
=>
RocksDBResult
::
Some
(
x
),
RocksDBResult
::
None
=>
RocksDBResult
::
None
,
RocksDBResult
::
None
=>
RocksDBResult
::
None
,
...
@@ -266,7 +263,7 @@ impl <'a,T,E> RocksDBResult<'a,T,E> {
...
@@ -266,7 +263,7 @@ impl <'a,T,E> RocksDBResult<'a,T,E> {
}
}
}
}
pub
fn
on_absent
<
F
:
FnOnce
()
->
()
>
(
self
,
f
:
F
)
->
RocksDBResult
<
'a
,
T
,
E
>
{
pub
fn
on_absent
<
F
:
FnOnce
()
->
()
>
(
self
,
f
:
F
)
->
RocksDBResult
<
T
,
E
>
{
match
self
{
match
self
{
RocksDBResult
::
Some
(
x
)
=>
RocksDBResult
::
Some
(
x
),
RocksDBResult
::
Some
(
x
)
=>
RocksDBResult
::
Some
(
x
),
RocksDBResult
::
None
=>
{
RocksDBResult
::
None
=>
{
...
...
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