| Crates.io | fiftyonedegrees |
| lib.rs | fiftyonedegrees |
| version | 0.2.20 |
| created_at | 2019-10-27 21:29:32.003929+00 |
| updated_at | 2023-02-21 00:42:05.615388+00 |
| description | A wrapper around the 51Degrees device detection C library. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 176235 |
| size | 1,872,381 |
use fiftyonedegrees::properties::PropertyName;
use fiftyonedegrees::api::DeviceDetection;
fn main() {
let properties = vec![PropertyName::IsMobile];
let engine = DeviceDetection::new("path/to/file.hash", properties);
let result = engine.lookup("my user agent");
let boolean = result.getValueAsBoolean(&PropertyName::IsMobile).unwrap().unwrap();
let string = result.getValueAsString(&PropertyName::BrowserName).unwrap().unwrap();
}
Install Rust
https://www.rust-lang.org/tools/install
Install bindgen
cargo install bindgen-cli
Download c code
git submodule update --init --recursive
Point git submodule to target tag
cd device-detection-cxx
git checkout 4.2.3
cd src/common-cxx
git submodule update
Regenerate c bindings for rust
bindgen src/shim/wrapper.h -o src/shim/mod.rs
Run tests
cargo test
cargo run --example benchmark --release