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
use model::ModelWithConfig;
use pose_detector::PoseDetector;
use wasm_bindgen::JsValue;
use wasm_bindgen_futures::JsFuture;

mod bindings;
mod call_method;
pub mod model;
pub mod pose;
pub mod pose_detector;
pub mod util;

pub enum BackendName {
    Webgl,
    Cpu,
    Tensorflow,
}

impl ToString for BackendName {
    fn to_string(&self) -> String {
        match self {
            BackendName::Cpu => "cpu",
            BackendName::Webgl => "webgl",
            BackendName::Tensorflow => "tensorflow",
        }
        .into()
    }
}

pub async fn create_detector(model: ModelWithConfig) -> Result<PoseDetector, JsValue> {
    let name = &model.get_name()[..];
    let config = model.get_config();
    let detector_js_value = JsFuture::from(bindings::create_detector(name, &config))
        .await
        .unwrap();
    Ok(PoseDetector::from(detector_js_value))
}