Skip to content

Commit 4246a4e

Browse files
committed
No need for an extra Rust class
1 parent 1d9fc43 commit 4246a4e

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

java/javacalclib/src/lib.rs

+2-24
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,14 @@ use jni::objects::JClass;
1212

1313
use jni::sys::jlong;
1414

15-
struct Calc {
16-
instance: calclib::Calc,
17-
}
18-
19-
impl Calc {
20-
pub fn new() -> Self {
21-
Self {
22-
instance: calclib::Calc::new(0.0),
23-
}
24-
}
25-
26-
pub fn add(&mut self, value: c_double) -> f64 {
27-
self.instance.add(value)
28-
}
29-
30-
pub fn sub(&mut self, value: c_double) -> f64 {
31-
self.instance.sub(value)
32-
}
33-
34-
pub fn result(&self) -> f64 {
35-
self.instance.result()
36-
}
37-
}
15+
use calclib::Calc;
3816

3917
/// # Safety
4018
///
4119
/// This function creates a new instance.
4220
#[no_mangle]
4321
pub unsafe extern "system" fn Java_JavaCalcTest_calcNew(_env: JNIEnv, _class: JClass) -> jlong {
44-
let calc = Calc::new();
22+
let calc = Calc::new(0.0);
4523

4624
Box::into_raw(Box::new(calc)) as jlong
4725
}

0 commit comments

Comments
 (0)