Struct Device

Source
pub struct Device { /* private fields */ }

Implementations§

Source§

impl Device

Source

pub fn device_type(&self) -> &DeviceType

Examples found in repository?
examples/create.rs (line 78)
73fn find_device(manager: &NetworkManager) -> Result<Device> {
74    let devices = manager.get_devices()?;
75
76    let index = devices
77        .iter()
78        .position(|d| *d.device_type() == DeviceType::WiFi);
79
80    if let Some(index) = index {
81        Ok(devices[index].clone())
82    } else {
83        bail!(ErrorKind::Runtime("Cannot find a WiFi device".into()))
84    }
85}
More examples
Hide additional examples
examples/hotspot.rs (line 115)
111fn find_device(manager: &NetworkManager, interface: Option<String>) -> Result<Device> {
112    if let Some(interface) = interface {
113        let device = manager.get_device_by_interface(&interface)?;
114
115        if *device.device_type() == DeviceType::WiFi {
116            Ok(device)
117        } else {
118            bail!(ErrorKind::Runtime(format!(
119                "{} is not a WiFi device",
120                interface
121            )))
122        }
123    } else {
124        let devices = manager.get_devices()?;
125
126        let index = devices
127            .iter()
128            .position(|d| *d.device_type() == DeviceType::WiFi);
129
130        if let Some(index) = index {
131            Ok(devices[index].clone())
132        } else {
133            bail!(ErrorKind::Runtime("Cannot find a WiFi device".into()))
134        }
135    }
136}
Source

pub fn interface(&self) -> &str

Source

pub fn get_state(&self) -> Result<DeviceState>

Source

pub fn as_wifi_device(&self) -> Option<WiFiDevice<'_>>

Examples found in repository?
examples/hotspot.rs (line 67)
52fn run() -> Result<()> {
53    let Options {
54        interface,
55        ssid,
56        password,
57    } = parse_options();
58
59    let pass_str = match password {
60        Some(ref s) => Some(s as &str),
61        None => None,
62    };
63
64    let manager = NetworkManager::new();
65
66    let device = find_device(&manager, interface)?;
67    let wifi_device = device.as_wifi_device().unwrap();
68
69    wifi_device.create_hotspot(&ssid as &str, pass_str, None)?;
70
71    Ok(())
72}
More examples
Hide additional examples
examples/create.rs (line 58)
46fn run() -> Result<()> {
47    let args: Vec<String> = env::args().collect();
48
49    if args.len() != 3 {
50        println!("USAGE: create SSID PASSWORD");
51        process::exit(1);
52    }
53
54    let manager = NetworkManager::new();
55
56    let device = find_device(&manager)?;
57
58    let wifi_device = device.as_wifi_device().unwrap();
59
60    let access_points = wifi_device.get_access_points()?;
61
62    let ap_index = find_access_point(&access_points, &args[1] as &str)?;
63
64    let credentials = AccessPointCredentials::Wpa {
65        passphrase: args[2].clone(),
66    };
67
68    wifi_device.connect(&access_points[ap_index], &credentials)?;
69
70    Ok(())
71}
Source

pub fn connect(&self) -> Result<DeviceState>

Connects a Network Manager device.

Examples

use network_manager::{NetworkManager, DeviceType};
let manager = NetworkManager::new();
let devices = manager.get_devices().unwrap();
let i = devices.iter().position(|ref d| *d.device_type() == DeviceType::WiFi).unwrap();
devices[i].connect().unwrap();
Source

pub fn disconnect(&self) -> Result<DeviceState>

Disconnect a Network Manager device.

§Examples
use network_manager::{NetworkManager, DeviceType};
let manager = NetworkManager::new();
let devices = manager.get_devices().unwrap();
let i = devices.iter().position(|ref d| *d.device_type() == DeviceType::WiFi).unwrap();
devices[i].disconnect().unwrap();

Trait Implementations§

Source§

impl Clone for Device

Source§

fn clone(&self) -> Device

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Device

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Device

§

impl !RefUnwindSafe for Device

§

impl !Send for Device

§

impl !Sync for Device

§

impl Unpin for Device

§

impl !UnwindSafe for Device

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.