1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
pub use c::*;

pub mod comparator;
pub mod slice_transform;

#[allow(non_upper_case_globals)]
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
mod c;

pub fn version() -> String {
    unsafe {
        format!(
            "{}.{}.{}",
            rocks_version_major(),
            rocks_version_minor(),
            rocks_version_patch()
        )
    }
}

#[test]
fn test_smoke() {
    assert!(version().len() > 0);
}

#[no_mangle]
pub extern "C" fn bz_internal_error(errcode: i32) {
    assert!(errcode == 0);
}

#[doc(hidden)]
pub mod rust_export {
    use std::ptr;

    #[no_mangle]
    pub extern "C" fn rust_hello_world() {
        println!("Hello World! from rust");
    }

    #[no_mangle]
    pub unsafe extern "C" fn rust_string_assign(s: *mut String, p: *const u8, len: usize) {
        (*s).reserve(len);
        ptr::copy(p, (*s).as_mut_vec().as_mut_ptr(), len);
        (*s).as_mut_vec().set_len(len);
    }

    #[no_mangle]
    pub unsafe extern "C" fn rust_vec_u8_assign(v: *mut Vec<u8>, p: *const u8, len: usize) {
        // (*v).extend_from_slice(slice::from_raw_parts(p, len))
        (*v).reserve(len);
        ptr::copy(p, (*v).as_mut_ptr(), len);
        (*v).set_len(len);
    }
}