#[non_exhaustive]pub struct Network {
pub kind: NetworkKind,
pub expensive: bool,
pub constrained: bool,
pub cellular_data: CellularData,
}Expand description
How the device reaches the network now (network()), as the system’s
path monitor reports it: the kind of link its default route takes,
whether that link costs the user (expensive) or the user asked to save
data on it (constrained), and on iOS whether the user lets the app use
cellular data. Platforms that cannot tell report
NetworkKind::Unknown, which counts as online: the app tries and
learns from its requests.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.kind: NetworkKindThe kind of link the default route takes, NetworkKind::None
without one.
expensive: boolThe link costs the user: cellular data, a phone’s hotspot, a
metered connection (Apple’s isExpensive, Android’s metered
networks, the browser’s cellular connection).
constrained: boolThe user asked to use less data on this link: Low Data Mode (iOS,
macOS), Data Saver (Android), the browser’s saveData.
cellular_data: CellularDataWhether the user lets the app use cellular data (iOS:
CTCellularData; on devices sold in mainland China, the system’s
prompt for wireless data). CellularData::Unknown elsewhere.
Implementations§
Source§impl Network
impl Network
Sourcepub fn new(kind: NetworkKind) -> Self
pub fn new(kind: NetworkKind) -> Self
A network of kind, neither expensive nor constrained, with the
cellular data permission unknown.
Sourcepub fn constrained(self, constrained: bool) -> Self
pub fn constrained(self, constrained: bool) -> Self
The user asked to use less data on this link.
Sourcepub fn cellular_data(self, cellular_data: CellularData) -> Self
pub fn cellular_data(self, cellular_data: CellularData) -> Self
Whether the user lets the app use cellular data.
Sourcepub fn online(&self) -> bool
pub fn online(&self) -> bool
Whether a route to the network exists (TS: network().online):
false only when the platform knows there is none, true while it
does not know (NetworkKind::Unknown).