#properties #devices #detection #device-detection #51degrees

fiftyonedegrees

A wrapper around the 51Degrees device detection C library

22 releases

0.2.20 Feb 21, 2023
0.2.19 Feb 20, 2023
0.2.18 Dec 17, 2022
0.2.17 Jun 29, 2021
0.1.1 Oct 27, 2019

#325 in Data structures

Download history

54 downloads per month

MIT license

1.5MB
32K SLoC

Rust 20K SLoC // 0.0% comments C 9K SLoC // 0.2% comments C++ 2.5K SLoC // 0.2% comments SWIG 536 SLoC // 0.5% comments

Usage

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();
}

Development

Install Rust

https://www.rust-lang.org/tools/install

Install bindgen

cargo install bindgen-cli

Download c code

git submodule update --init --recursive

Updating to latest device-detection-cxx

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

Performance Benchmarking

cargo run --example benchmark --release

No runtime deps