WURFL InFuze Module for rust : User Guide
=======================================

WURFL InFuze for rust is a Rust language module wrapping the WURFL C API and
encapsulating it in two rust types to provide a fast and intuitive
interface. It is compatible on `linux` platforms for Rust `edition 2021`, version 1.85 and higher.

Installing libwurfl
-------------------

In order for the Module to work it is **ESSENTIAL** that the `libwurfl` library is installed on your system.
`libwurfl` is provided in the **Downloads** section of your license in the [Customer Vault](https://my.scientiamobile.com/account).

If you have not already installed libwurfl,
instructions can be found [here](https://docs.scientiamobile.com/documentation/infuze/infuze-c-api-user-guide).
Changes in each release are listed in the [WURFL InFuze API Changelog](https://docs.scientiamobile.com/documentation/changelog/infuze-api-change-log).


Installation on Linux
-----------------------------

InFuze for Rust is available as a source code package. In order to use it, you have to install Rust and Cargo (the rust build and execution tool).

You can install Rust and Cargo with this command: `curl https://sh.rustup.rs -sSf | sh`

If everything goes fine, this message will appear: "Rust is installed now. Great!"


Unpack the contents of the rust-wurfl package in a directory of choice. For example: `tar xvzf rust-mod_wurfl-W.X.Y.Z.tar.gz`

You can build the `wurfl` to use it as a library with the command `cargo build --lib` from the rust-wurfl project root.

WURFL Data Snapshot
-----
To perform lookups, you will need a copy of your WURFL data snapshot (also referred to as the `wurfl.xml`). While there is one included in the release package, it is intended to be a sample and will not contain all of your licensed capabilities. Your licensed WURFL data snapshot can be accessed by [following these directions](https://docs.scientiamobile.com/guides/wurfl-snapshot-generator).
Usage
-----

Here is an example to get started:

```rust
use wurfl::*;
use std::collections::HashMap;

fn main() {
    println!("Starting WURFL wrapper usage sample!");

    // download WURFL file from the ScientiaMobile Snapshot generator (replace the sample URL with your own specific customer URL to avoid error 402)
    // we use the current directory as destination
    let download_res = wurfl_download("https://data.scientiamobile.com/xxxxx/wurfl.zip", ".");
    match download_res {
        Ok(_) => println!("WURFL file downloaded successfully"),
        Err(_) => println!("WURFL file downloaded FAILED: keeping default version"),
    }

    // create the engine using the WURFL file downloaded in the current directory
    let wurfl_path = "wurfl.zip";
    let wurfl_res = Wurfl::new(wurfl_path, None, None, WurflCacheProvider::LRU, Some("100000"));
    let engine = match wurfl_res {
        Ok(engine) => engine,
        Err(error) => panic!("Problem initializing wurfl: {:?}", error),
    };
    println!("WURFL API Version created: {}", engine.get_api_version());

    let ua = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Mobile Safari/537.36";
    // Create headers
    let mut headers = HashMap::new();
    headers.insert("User-Agent", ua);
    headers.insert("Sec-Ch-Ua", "\"Chromium\";v=\"94\", \"HuaweiBrowser\";v=\"99\", \";Not A Brand\";v=\"99\"");
    headers.insert("Sec-Ch-Ua-Full-Version", "99.123.456");
    headers.insert("Sec-Ch-Ua-Platform", "Android");
    headers.insert("Sec-Ch-Ua-Platform-Version", "12");
    headers.insert("Sec-Ch-Ua-Model", "Pixel 6");

    // lookup the device with the headers and Client Hints
    let device_res = engine.lookup_with_headers(headers);
    match device_res {
        Ok(d) => {
            println!("Device ID: {}", d.get_device_id());

            match d.get_virtual_cap("complete_device_name") {
                Ok(Some(device_name)) => println!("Complete device name: {}", device_name),
                Ok(None) => println!("Complete device name not available."),
                Err(e) => eprintln!("Error retrieving 'complete_device_name': {}", e),
            }

            match d.get_virtual_cap("is_smartphone") {
                Ok(Some(is_smartphone)) => println!("Device is smartphone?: {}", is_smartphone),
                Ok(None) => println!("Information about whether the device is a smartphone is not available."),
                Err(e) => eprintln!("Error retrieving 'is_smartphone': {}", e),
            }
        }
        Err(_) => panic!("Lookup user agent failed"),
    };
}


```

You can also compile and run the example application with the command:

`cargo run --package wurfl --example example`

This code snippet creates the WURFL Engine once, then performs a lookup with a UserAgent string (you can also use any struct that implements the `IntoIterator` trait and contains the request headers directly using `engine.lookup_with_headers`) and get the static and virtual capabilities needed in your implementation (**NOTE:** virtual capabilities are calculated at runtime).

### <a name="updater"></a>
WURFL Updater
-------------

If you want to keep your `wurfl.zip` up-to-date with the ScientiaMobile data release schedule, then you might want to use the Updater features.

After creating your WURFL Engine, set your personal WURFL Snapshot URL
(in the form "https://data.scientiamobile.com/xxxxx/wurfl.zip", available on the **Snapshot generator** page of your license in the [Customer Vault](https://my.scientiamobile.com/account)):

```rust
let we = engine.set_updater_data_url(wurfl_download_url);
    let no_error = we.is_none();
    // handle error or Ok cases ...
```

Specify the periodicity you would like for update checks (for example, the Daily update frequency):

```
let we = engine.set_updater_data_frequency(WurflUpdaterFrequency::WurflUpdaterFrequencyDaily);
```

Do note that a wurfl.zip file must already be present in a writable path in order for the updater to check the file and determine whether or not it needs to update the file.

Start the updater:

```
let we_h = engine.updater_start();
```

Updater will run a daily check for the latest release of the `wurfl.zip` file, download it, and update the running engine to the latest version - all during normal application operations.

Updater methods usually return an `Option<WurflError>`


API Reference
-------------

## <a name="pkg-index"></a>Index
* [Constants](#pkg-constants)
* [type Device](#Device)
    * [fn get\_capabilities](#fn-get_capabilities)
    * [fn get\_virtual\_capabilities](#fn-get_virtual_capabilities)
    * [fn get\_static_cap](#fn-get_static_cap)
    * [fn get\_device\_id](#-fn-get_device_id)
    * [fn get\_match\_type](#fn-get_match_type)
    * [fn (\*Device) get\_normalized\_user\_agent](#fn-device-get_normalized_user_agent)
    * [fn get\_original\_user\_agent](#fn-get_original_user_agent)
    * [fn get\_root\_id](#fn-get_root_id)
    * [fn get\_user\_agent](#fn-get_user_agent)
    * [fn get\_virtual\_cap](#fn-get_virtual_cap)
    * [fn is\_root](#fn-is_root)
* [fn wurfl\_download](#fn-wurfl_download)
* [type Wurfl](#Wurfl)
    * [fn new](#fn-new)
    * [fn get\_api\_version](#fn-get_api_version)
    * [fn get\_all\_caps](#fn-get_all_caps)
    * [fn get\_all\_vcaps](#fn-get_all_vcaps)
    * [fn get\_info](#fn-get_info)
    * [fn get\_last\_load\_time](#fn-get_last_load_time)
    * [fn has\_capability](#fn-has_capability)
    * [fn has\_virtual\_capability](#fn-has_virtual_capability)
    * [fn lookup\_device\_id](#fn-lookup_device_id)
    * [fn lookup\_device\_id\_with\_headers](#fn-lookup_device_id_with_headers)
    * [fn lookup\_with\_headers](#fn-lookup_with_headers)
    * [fn lookup\_useragent](#fn-lookup_useragent)
    * [fn set\_updater\_data\_frequency](#fn-set_updater_data_frequency)
    * [fn set\_updater\_data\_url](#fn-set_updater_data_url)
    * [fn set\_updater\_data\_url\_timeout](#fn-set_updater_data_url_timeout)
    * [fn updater\_runonce](#fn-updater_runonce)
    * [fn updater\_start](#fn-updater_start)
    * [fn updater\_stop](#fn-updater_stop)




## <a name="pkg-constants"></a>Constants

Cache Provider possible values

``` rust
pub enum WurflCacheProvider {
    NoCache,
    LRU,
}
```

Match type

``` rust
pub enum Type {
    WurflMatchTypeExact,
    WurflMatchTypeConclusive,
    WurflMatchTypeRecovery,
    WurflMatchTypeCatchall,
    WurflMatchTypeNone,
    WurflMatchTypeCached,
}
```

Wurfl updater frequency


``` rust
pub enum WurflUpdaterFrequency {
    WurflUpdaterFrequencyDaily,
    WurflUpdaterFrequencyWeekly,
}
```




## <a name="Device"></a>type Device

Device provides access to device static and virtual capabilities



### <a name="fn-get_capabilities"></a>fn get_capabilities
``` rust
pub fn get_capabilities(&self,cap_names: &[&str]) -> Result<HashMap<String, String>, WurflError>]
```
Returns a map -> key:cap_name,value:cap_value for the calling device

### <a name="fn-get_virtual_capabilities"></a>fn get_virtual_capabilities
``` rust
pub fn get_virtual_capabilities(&self,vcap_names: &[&str]) -> Result<HashMap<String, String>, WurflError>]
```
Returns a map -> key:vcap_name,value:vcap_value for the calling device




### <a name="fn-get_static_cap"></a>fn get_static_cap
``` rust
pub fn get_static_cap(&self, capability_name: &str) -> Result<Option<&str>, WurflError>
```
Returns the device value of the static capability with the given name




### <a name="fn-get_device_id"></a> fn get_device_id
``` rust
pub fn get_device_id(&self) -> &str
```
Get wurfl_id string from device handle




### <a name="fn-get_match_type"></a>fn get_match_type
``` rust
 pub fn get_match_type(&self) -> MatchType 
```
Get type of Match occurred in lookup




### <a name="fn-get_normalized_user_agent"></a>fn (\*Device) get_normalized_user_agent
``` rust
pub fn get_normalized_user_agent(&self) -> &str {
```
Get the Normalized (processed by wurfl api) userAgent




### <a name="fn-get_original_user_agent"></a>fn get_original_user_agent
``` rust
pub fn get_original_user_agent(&self) -> &str
```
Get the original UserAgent of matched device (the one passed to lookup)




### <a name="fn-get_root_id"></a>fn get_root_id
``` rust
pub fn get_root_id(&self) -> &str 
```
Returns the unique ID of this device ancestor in the WURFL hierarchy.




### <a name="fn-get_user_agent"></a>fn get_user_agent
``` rust
pub fn get_user_agent(&self) -> &str
```
Get default UserAgent of matched device (might be different from UA passed to lookup)




### <a name="fn-get_virtual_cap"></a>fn get_virtual_cap
``` rust
pub fn get_virtual_cap(&self, virtual_capability_name: &str) -> Result<Option<&str>, WurflError>
```
Get Virtual Capability




### <a name="fn-is_root"></a>fn is_root
``` rust
pub fn is_root(&self) -> bool
```
Returns true if this device is a root device in the WURFL hierarchy



## <a name="fn-wurfl_download"></a>fn wurfl_download
``` rust
pub fn wurfl_download(url: &str, dest: &str) -> Result<(), WurflError>
```
Downloads a file from the given Snapshot Generator url to the given destination. 
The destination must exist and be writable.

Returns an error if the file could not be downloaded (connection error, write error, etc).


## <a name="Wurfl"></a>type Wurfl

WURFL holds data and exposes methods used to perform device detection and access device capabilities.



### <a name="fn-new"></a>fn new
``` rust
 pub fn new(wurfl_xml: &str, patches: Option<&[&str]>, cap_filter: Option<&[&str]>,
               cache_provider: WurflCacheProvider, cache_extra_config: Option<&str>) -> Result<Wurfl, WurflError>
```
Create the wurfl engine.
  Parameters :

    - wurfl_xml : path to the wurfl.xml/zip file
    - patches : vector of paths of patches files to load
    - cap_filter : don't use it (pass None as argument)
    - cache_provider : WurflCacheProviderLru or NoCache
    - cache_extra_config : size of lru cache in the form "100000"



### <a name="fn-get_api_version"></a>fn get_api_version
``` rust
pub fn get_api_version(&self) -> &str 
```
Returns version of internal InFuze API




### <a name="fn-get_all_caps"></a>fn get_all_caps
``` rust
pub fn get_all_caps(&self) -> Vec<String>
```
Return all capabilities names




### <a name="fn-get_all_vcaps"></a>fn get_all_vcaps
``` rust
pub fn get_all_vcaps(&self) -> Vec<String>
```
Returns all virtual capabilities names




### <a name="fn-get_info"></a>fn get_info
``` go
pub fn get_info(&self) -> &str
```
Get wurfl.xml info




### <a name="fn-get_last_load_time"></a>fn get_last_load_time
``` rust
pub fn get_last_load_time(&self) -> &str
```
Get last wurfl.xml load time



### <a name="fn-has_capability"></a>fn has_capability
``` rust
 pub fn has_capability(&self, cap_name: &str) -> bool
```
Return true if the capability exists




### <a name="fn-has_virtual_capability"></a>fn has_virtual_capability
``` go
 pub fn has_virtual_capability(&self, vcap_name: &str) -> bool
```
Return true if the virtual capability exists




### <a name="fn-lookup_device_id"></a>fn lookup_device_id
``` rust
pub fn lookup_device_id(&self, device_id: &str) -> Result<Device, WurflError>
```
Lookup by wurfl_ID and return Device handle




### <a name="fn-lookup_device_id_with_headers"></a>fn lookup_device_id_with_headers
``` go
pub fn lookup_device_id_with_headers<U, V, T: IntoIterator<Item=(U, V)>>(&self, device_id: &str, headers: T) -> Result<Device, WurflError>
```
Lookup by wurfl_ID and request headers and return Device handle




### <a name="fn-lookup_with_headers"></a>fn lookup_with_headers
``` go
pub fn lookup_with_headers<U, V, T: IntoIterator<Item=(U, V)>>(&self, headers: T) -> Result<Device, WurflError> where U: ToString, V: AsRef<[u8]> 
```
Lookup Request and return Device handle




### <a name="fn-LookupUserAgent"></a>fn lookup_useragent
``` rust
pub fn lookup_useragent(&self, user_agent: &str) -> Result<Device, WurflError> 
```
Lookup up useragent and return Device handle




### <a name="fn-set_updater_data_frequency"></a>fn set_updater_data_frequency
``` rust
pub fn set_updater_data_frequency(&self, freq: WurflUpdaterFrequency) -> Option<WurflError> 
```
Set interval of update checks




### <a name="fn-set_updater_data_url"></a>fn set_updater_data_url
``` rust
pub fn set_updater_data_url(&self, data_url: &str) -> Option<WurflError>
```
Set your HTTPS updater URL, as shown on your **Snapshot generator** page in the Customer Vault




### <a name="fn-set_updater_data_url_timeout"></a>fn set_updater_data_url_timeout
``` rust
pub fn set_updater_data_url_timeout(&self, conn_timeout: i32, data_transfer_timeout: i32) -> Option<WurflError>
```
Set path of updater log file



### <a name="fn-updater_runonce"></a>fn updater_runonce
``` rust
 pub fn updater_runonce(&self) -> Option<WurflError> 
```
Start updater process once and wait for termination




### <a name="fn-updater_start"></a>fn updater_start
``` rust
 pub fn updater_start(&self) -> Option<WurflError>
```
Start the updater thread




### <a name="fn-updater_stop"></a>fn updater_stop
``` rust
pub fn updater_stop(&self) -> Option<WurflError>
```
Stop the updater thread

- - -


-------

**&copy; 2026 ScientiaMobile Inc.<br>
All Rights Reserved.**

**NOTICE:** All information contained herein is, and remains the property of ScientiaMobile Incorporated
and its suppliers, if any.  The intellectual and technical concepts contained herein are proprietary to
ScientiaMobile Incorporated and its suppliers and may be covered by U.S. and Foreign Patents, patents
in process, and are protected by trade secret or copyright law. Dissemination of this information or
reproduction of this material is strictly forbidden unless prior written permission is obtained from
ScientiaMobile Incorporated.
