-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
36 lines (27 loc) · 692 Bytes
/
lib.rs
File metadata and controls
36 lines (27 loc) · 692 Bytes
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
use ffi::*;
//#[cxx::bridge(namespace = "org::environment")]
use cxx::CxxVector;
#[cxx::bridge]
mod ffi {
extern "Rust" {
type Environment;
fn new_environment() -> Box<Environment>;
fn print_secret_weight(&self)->f64;
fn weighted_sum_vector(&self, vec: &CxxVector<f64>)->f64;
}
}
fn new_environment () -> Box<Environment> {
Box::new(Environment{ weight: 2.0})
}
struct Environment {
weight : f64
}
impl Environment {
fn print_secret_weight(&self) -> f64 {
self.weight
}
fn weighted_sum_vector(&self, my_vec: &CxxVector<f64>)-> f64 {
let my_sum : f64 =my_vec.iter().sum() ;
my_sum*self.weight
}
}