Skip to main content

Crate is_metered_network

Crate is_metered_network 

Source
Expand description

Cross-platform detection of whether the current network connection is metered.

A metered connection is one where the operating system (or the user) has indicated that data usage may be limited or billed, e.g. cellular data, a mobile hotspot or a capped plan. Applications can use this to avoid large background transfers on such connections.

PlatformSource
Windowsthe Network List Manager COM API (INetworkCostManager::GetCost)
Linuxthe Metered property of org.freedesktop.NetworkManager on the D-Bus system bus

macOS is not supported yet.

§Usage

if is_metered_network::check()? {
    println!("on a metered connection");
}

For the underlying cost instead of a plain bool (e.g. to distinguish a known-unmetered connection from an unknown one), use connection_cost:

println!("{}", is_metered_network::connection_cost()?);

Enums§

ConnectionCost
The cost/metered status of a network connection.

Functions§

check
Returns true if the current network connection is metered.
connection_cost
Returns the cost/metered status of the current primary network connection.