Skip to main content

Net

Struct Net 

Source
pub struct Net { /* private fields */ }
Expand description

The single public API facade exposed by net-kit.

Net itself is only responsible for lifecycle management and forwarding; all of the actual runtime and network-monitoring logic lives in the internal [InnerNet], ensuring isolation.

Implementations§

Source§

impl Net

Source

pub fn new() -> Net

Create an instance only; does not start network monitoring.

Source

pub async fn start(&self) -> Result<(), NetError>

Start network monitoring. Redundant calls are ignored; start may be called again after shutdown.

Internally creates and owns a runtime engine owned by net-kit.

Source

pub async fn start_with_tokio_rt( &self, runtime_handle: Handle, ) -> Result<(), NetError>

Start network monitoring. Redundant calls are ignored; start may be called again after shutdown.

Uses a Tokio runtime supplied by the developer. The caller is responsible for keeping that runtime alive; shutdown does not close it.

Source

pub fn shutdown(&self) -> Result<(), NetError>

Stop network monitoring and destroy all resources created by start. Redundant calls are ignored.

Source

pub fn local_network_reachability(&self) -> Result<NetworkStatus, NetError>

Query whether the network is currently available.

Returns NetworkStatus::Unavailable when not started; returns NetError::Lock if an internal lock is poisoned, leaving recovery to the developer.

Source

pub fn register( &self, listener: NetworkStatusListener, ) -> Result<Option<NetworkStatusListenerHandle>, NetError>

Register a network notification listener; multiple may be registered.

Returns Ok(None) when not started; Ok(Some(handle)) on success after start; returns NetError::Lock if an internal lock is poisoned.

Source

pub fn unregister( &self, handle: NetworkStatusListenerHandle, ) -> Result<bool, NetError>

Unregister a network notification listener by handle.

Returns Ok(false) when not started; Ok(true) when a listener was found and removed; returns NetError::Lock if an internal lock is poisoned.

Source

pub fn clear_all_listener(&self) -> Result<(), NetError>

Clear all registered network listeners. Returns NetError::NotStarted when not started.

Source

pub fn is_started(&self) -> bool

Query whether network monitoring is currently started.

Returns true while an engine is installed (i.e. after start and before shutdown); returns false otherwise. A poisoned internal lock is treated as not started, so this method never panics and never returns an error.

Source

pub fn is_shutdown(&self) -> bool

Query whether network monitoring is currently shut down (i.e. not started).

This is the logical inverse of Net::is_started: it returns true before the first start and after every shutdown. A poisoned internal lock is treated as not started, so this method never panics and never returns an error.

Source

pub fn get_current_network_name(&self) -> Result<Option<String>, NetError>

Query the name of the network the host is currently connected to.

Returns Ok(None) when not started; Ok(Some(name)) when started and a connected network name could be resolved; Ok(None) when started but no name is available (or the platform is unsupported); returns NetError::Lock if an internal lock is poisoned.

Source

pub fn set_log_listener( &self, listener: Option<LogListener>, ) -> Result<(), NetError>

Install (or clear, with None) a listener for the engine’s internal diagnostic log records.

Returns NetError::NotStarted when not started; returns NetError::Lock if an internal lock is poisoned.

Trait Implementations§

Source§

impl Default for Net

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !Freeze for Net

§

impl RefUnwindSafe for Net

§

impl Send for Net

§

impl Sync for Net

§

impl Unpin for Net

§

impl UnsafeUnpin for Net

§

impl UnwindSafe for Net

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more