Device Detection and IP Intelligence for the 51Degrees Pipeline, in Rust

ipi-onprem-compare.rs File Reference

Classes

struct  ExampleOptions
 Options the example runs with. More...

Functions

pub fn run (options:&ExampleOptions, out:&mut dyn Write) -> anyhow::Result<()>
 Run the compare example, writing all output to out.
fn lookup (data_file:&std::path::Path, profile:PerformanceProfile, ip:&str, available:&[String],) -> anyhow::Result< Vec< String > >
 Build a pipeline for one profile and look an IP up, returning the rendered value of each compared property.
fn compare_across_profiles (options:&ExampleOptions, available:&[String], out:&mut dyn Write,) -> anyhow::Result<()>
 Look the first IP up under each profile and show the results side by side, confirming that the choice of profile does not change the result.
fn compare_two_ips (options:&ExampleOptions, available:&[String], out:&mut dyn Write,) -> anyhow::Result<()>
 Compare the two IP addresses against each other under one profile.
fn main () -> anyhow::Result<()>
 Read the data file, then run the example, writing to standard output.
fn compare_runs_across_profiles_and_ips ()

Variables

const CONTACT_US_URL
 Where to ask about a copy of the Enterprise data file.
const & str
pub struct ExampleOptions PerformanceProfile = PerformanceProfile::LowMemory
 The profile the two IP addresses are compared under unless --profile names another.
const FASTER_PROFILE_COMMAND
 The command that compares the two IP addresses with the faster profile.
impl ExampleOptions
const ENTERPRISE_COMPARED
 The compared properties only the Enterprise data file carries.
const Town
const REQUESTED_PROPERTIES
 The properties the pipeline is asked for.
const AsnName
const RegisteredName
const Country
mod tests

Function Documentation

◆ compare_across_profiles()

fn compare_across_profiles ( options:& ExampleOptions,
available:& [String],
out:&mut dyn Write ) -> anyhow::Result<()>

Look the first IP up under each profile and show the results side by side, confirming that the choice of profile does not change the result.

◆ compare_runs_across_profiles_and_ips()

fn compare_runs_across_profiles_and_ips ( )

◆ compare_two_ips()

fn compare_two_ips ( options:& ExampleOptions,
available:& [String],
out:&mut dyn Write ) -> anyhow::Result<()>

Compare the two IP addresses against each other under one profile.

◆ lookup()

fn lookup ( data_file:&std::path::Path ,
profile:PerformanceProfile ,
ip:& str,
available:& [String] ) -> anyhow::Result< Vec< String > >

Build a pipeline for one profile and look an IP up, returning the rendered value of each compared property.

available holds the properties the data file carries.

◆ main()

fn main ( ) -> anyhow::Result<()>

Read the data file, then run the example, writing to standard output.

◆ run()

pub fn run ( options:& ExampleOptions,
out:&mut dyn Write ) -> anyhow::Result<()>

Run the compare example, writing all output to out.

Usage sharing is not enabled, as this is a console example.

Variable Documentation

◆ AsnName

const AsnName

◆ CONTACT_US_URL

const CONTACT_US_URL

Where to ask about a copy of the Enterprise data file.

◆ Country

const Country

◆ ENTERPRISE_COMPARED

const ENTERPRISE_COMPARED

The compared properties only the Enterprise data file carries.

◆ ExampleOptions

impl ExampleOptions
Initial value:
{
pub fn from_env() -> Option<Self> {
Self::for_tier(examples_shared::IpiTier::EnterpriseOrLite)
}
pub fn for_tier(tier: examples_shared::IpiTier) -> Option<Self> {
data_file: examples_shared::ipi_data_path(tier)?,
profiles: vec![
PerformanceProfile::HighPerformance,
PerformanceProfile::LowMemory,
PerformanceProfile::Balanced,
],
ips: ("1.1.1.1".to_owned(), "8.8.8.8".to_owned()),
profile: DEFAULT_PROFILE,
})
}
}
const COMPARED_PROPERTIES: &[&str] = &["Asn", "RegisteredName", "Country", "Town"]
if let Some(published)
const & str
Definition dd-cloud-configurator.rs:40
pub data_file
The path to the on-premise Hash data file the engine loads.
Definition dd-onprem-getting-started.rs:79
pub pub profile
The performance profile to load the data file with.
Definition dd-onprem-getting-started.rs:82
pub fn from_env() -> Option< Self >
Build the default options through the shared resolver.
Definition ipi-onprem-getting-started.rs:93
pub pub ips
The IP addresses to look up, as client-IP evidence values.
Definition ipi-onprem-getting-started.rs:82
pub fn for_tier(tier:examples_shared::IpiTier) -> Option< Self >
Build options pinned to a specific data-file tier.
Definition ipi-onprem-getting-started.rs:113
Options the example runs with.
Definition dd-cloud-configurator.rs:54

◆ FASTER_PROFILE_COMMAND

const FASTER_PROFILE_COMMAND

The command that compares the two IP addresses with the faster profile.

◆ PerformanceProfile

pub struct ExampleOptions PerformanceProfile = PerformanceProfile::LowMemory

The profile the two IP addresses are compared under unless --profile names another.

LowMemory reads the data file from disk, so the comparison needs little memory even with the Enterprise file, which is over 6 GB. Reading from disk is much slower, and the .NET metrics example read a profile's values about 166 times a second with LowMemory against 2,013 with the file held in memory, so --profile HighPerformance is offered where there is memory for the whole file.

◆ RegisteredName

const RegisteredName

◆ REQUESTED_PROPERTIES

const REQUESTED_PROPERTIES

The properties the pipeline is asked for.

AsnName and RegisteredName are included so the request holds a property each free file carries, because a data file opens only when it carries at least one property asked for.

◆ str

const & str
Initial value:
= &[
("IP Intelligence", "/ip-intelligence?utm_source=code&utm_medium=example&utm_campaign=51degrees-rust&utm_content=examples-ip-intelligence-examples-src-bin-ipi-onprem-compare.rs&utm_term=find-out-more"),
("Pricing", "/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-rust&utm_content=examples-ip-intelligence-examples-src-bin-ipi-onprem-compare.rs&utm_term=find-out-more"),
("Documentation", "/documentation/index.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-rust&utm_content=examples-ip-intelligence-examples-src-bin-ipi-onprem-compare.rs&utm_term=find-out-more"),
]

◆ tests

mod tests
Initial value:
{
use super::*

◆ Town

const Town