Skip to main content

NetworkService

Struct NetworkService 

Source
pub struct NetworkService {
    pub settings: Arc<Settings>,
    pub wifi: Property<Option<Arc<Wifi>>>,
    pub wired: Property<Option<Arc<Wired>>>,
    pub primary: Property<ConnectionType>,
    /* private fields */
}
Expand description

Entry point for network management. See crate-level docs for usage.

Fields§

§settings: Arc<Settings>

Connection profile management.

§wifi: Property<Option<Arc<Wifi>>>

WiFi device, if present (live-updated on hot-plug).

§wired: Property<Option<Arc<Wired>>>

Wired device, if present (live-updated on hot-plug).

§primary: Property<ConnectionType>

Primary connection type as reported by NetworkManager.

Implementations§

Source§

impl NetworkService

Source

pub async fn new() -> Result<Self, Error>

Starts the network service and initializes all components.

Performs device discovery, creates WiFi and wired service instances for available devices, and sets up property monitoring. Handles the actual initialization logic for the service.

§Errors

Returns NetworkError::ServiceInitializationFailed if:

  • D-Bus connection fails
  • Device discovery encounters errors
  • Device proxy creation fails
Source

pub async fn connection( &self, path: OwnedObjectPath, ) -> Result<ActiveConnection, Error>

Objects that implement the Connection.Active interface represent an attempt to connect to a network using the details provided by a Connection object.

§Errors

Returns NetworkError::ObjectNotFound if the connection doesn’t exist. Returns NetworkError::DbusError if DBus operations fail.

Source

pub async fn connection_monitored( &self, path: OwnedObjectPath, ) -> Result<Arc<ActiveConnection>, Error>

Objects that implement the Connection.Active interface represent an attempt to connect to a network using the details provided by a Connection object. This variant monitors the connection for changes.

§Errors

Returns NetworkError::ObjectNotFound if the connection doesn’t exist. Returns NetworkError::DbusError if DBus operations fail.

Source

pub async fn access_point( &self, path: OwnedObjectPath, ) -> Result<AccessPoint, Error>

Wi-Fi Access Point.

§Errors

Returns NetworkError::ObjectNotFound if the access point doesn’t exist. Returns NetworkError::ObjectCreationFailed if access point creation fails.

Source

pub async fn access_point_monitored( &self, path: OwnedObjectPath, ) -> Result<Arc<AccessPoint>, Error>

Wi-Fi Access Point. This variant monitors the access point for changes.

§Errors

Returns NetworkError::ObjectNotFound if the access point doesn’t exist. Returns NetworkError::ObjectCreationFailed if access point creation fails.

Source

pub async fn connection_settings( &self, path: OwnedObjectPath, ) -> Result<ConnectionSettings, Error>

Represents a single network connection configuration.

§Errors

Returns NetworkError::ObjectNotFound if the connection profile doesn’t exist. Returns NetworkError::DbusError if DBus operations fail.

Source

pub async fn connection_settings_monitored( &self, path: OwnedObjectPath, ) -> Result<Arc<ConnectionSettings>, Error>

Represents a single network connection configuration. This variant monitors the connection settings for changes.

§Errors

Returns NetworkError::ObjectNotFound if the connection profile doesn’t exist. Returns NetworkError::DbusError if DBus operations fail.

Source

pub async fn device(&self, path: OwnedObjectPath) -> Result<Device, Error>

Represents a network device.

§Errors

Returns NetworkError::ObjectNotFound if the device doesn’t exist. Returns NetworkError::DbusError if DBus operations fail.

Source

pub async fn device_monitored( &self, path: OwnedObjectPath, ) -> Result<Arc<Device>, Error>

Represents a network device. This variant monitors the device for changes.

§Errors

Returns NetworkError::ObjectNotFound if the device doesn’t exist. Returns NetworkError::DbusError if DBus operations fail.

Source

pub async fn device_wifi( &self, path: OwnedObjectPath, ) -> Result<DeviceWifi, Error>

Represents a Wi-Fi device.

§Errors

Returns NetworkError::ObjectNotFound if the device doesn’t exist. Returns NetworkError::WrongObjectType if the device is not a WiFi device.

Source

pub async fn device_wifi_monitored( &self, path: OwnedObjectPath, ) -> Result<Arc<DeviceWifi>, Error>

Represents a Wi-Fi device. This variant monitors the device for changes.

§Errors

Returns NetworkError::ObjectNotFound if the device doesn’t exist. Returns NetworkError::WrongObjectType if the device is not a WiFi device.

Source

pub async fn device_wired( &self, path: OwnedObjectPath, ) -> Result<DeviceWired, Error>

Represents a wired Ethernet device.

§Errors

Returns NetworkError::ObjectNotFound if the device doesn’t exist. Returns NetworkError::WrongObjectType if the device is not an ethernet device.

Source

pub async fn device_wired_monitored( &self, path: OwnedObjectPath, ) -> Result<Arc<DeviceWired>, Error>

Represents a wired Ethernet device. This variant monitors the device for changes.

§Errors

Returns NetworkError::ObjectNotFound if the device doesn’t exist. Returns NetworkError::WrongObjectType if the device is not an ethernet device.

Source

pub async fn ip4_config( &self, path: OwnedObjectPath, ) -> Result<Ip4Config, Error>

IPv4 Configuration Set.

§Errors

Returns NetworkError::ObjectNotFound if the configuration doesn’t exist. Returns NetworkError::DbusError if DBus operations fail.

Source

pub async fn ip6_config( &self, path: OwnedObjectPath, ) -> Result<Ip6Config, Error>

IPv6 Configuration Set.

§Errors

Returns NetworkError::ObjectNotFound if the configuration doesn’t exist. Returns NetworkError::DbusError if DBus operations fail.

Source

pub async fn dhcp4_config( &self, path: OwnedObjectPath, ) -> Result<Dhcp4Config, Error>

DHCP4 Configuration.

§Errors

Returns NetworkError::ObjectNotFound if the configuration doesn’t exist. Returns NetworkError::DbusError if DBus operations fail.

Source

pub async fn dhcp6_config( &self, path: OwnedObjectPath, ) -> Result<Dhcp6Config, Error>

DHCP6 Configuration.

§Errors

Returns NetworkError::ObjectNotFound if the configuration doesn’t exist. Returns NetworkError::DbusError if DBus operations fail.

Source

pub async fn check_permissions_signal( &self, ) -> Result<impl Stream<Item = ()>, Error>

Emitted when system authorization details change.

§Errors

Returns error if D-Bus proxy creation fails.

Source

pub async fn state_changed_signal( &self, ) -> Result<impl Stream<Item = NMState>, Error>

NetworkManager’s state changed.

§Errors

Returns error if D-Bus proxy creation fails.

Source

pub async fn device_added_signal( &self, ) -> Result<impl Stream<Item = OwnedObjectPath>, Error>

A device was added to the system.

§Errors

Returns error if D-Bus proxy creation fails.

Source

pub async fn device_removed_signal( &self, ) -> Result<impl Stream<Item = OwnedObjectPath>, Error>

A device was removed from the system.

§Errors

Returns error if D-Bus proxy creation fails.

Trait Implementations§

Source§

impl Debug for NetworkService

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for NetworkService

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl ServiceMonitoring for NetworkService

Source§

type Error = Error

Error type for monitoring operations.
Source§

async fn start_monitoring(&self) -> Result<(), Self::Error>

Starts monitoring for state changes. Read more

Auto Trait Implementations§

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