@@ -7,9 +7,8 @@ use ascii::AsAsciiStr;
77use dbus_nm:: DBusNetworkManager ;
88
99use wifi:: Security ;
10- use device:: { Device , get_active_connection_devices} ;
11- use ssid:: { Ssid , SsidSlice , AsSsidSlice } ;
12-
10+ use device:: { get_active_connection_devices, Device } ;
11+ use ssid:: { AsSsidSlice , Ssid , SsidSlice } ;
1312
1413#[ derive( Clone ) ]
1514pub struct Connection {
@@ -64,14 +63,20 @@ impl Connection {
6463
6564 match state {
6665 ConnectionState :: Activated => Ok ( ConnectionState :: Activated ) ,
67- ConnectionState :: Activating => {
68- wait ( self , & ConnectionState :: Activated , self . dbus_manager . method_timeout ( ) )
69- } ,
66+ ConnectionState :: Activating => wait (
67+ self ,
68+ & ConnectionState :: Activated ,
69+ self . dbus_manager . method_timeout ( ) ,
70+ ) ,
7071 ConnectionState :: Unknown => Err ( "Unable to get connection state" . to_string ( ) ) ,
7172 _ => {
7273 self . dbus_manager . activate_connection ( & self . path ) ?;
7374
74- wait ( self , & ConnectionState :: Activated , self . dbus_manager . method_timeout ( ) )
75+ wait (
76+ self ,
77+ & ConnectionState :: Activated ,
78+ self . dbus_manager . method_timeout ( ) ,
79+ )
7580 } ,
7681 }
7782 }
@@ -91,9 +96,11 @@ impl Connection {
9196
9297 match state {
9398 ConnectionState :: Deactivated => Ok ( ConnectionState :: Deactivated ) ,
94- ConnectionState :: Deactivating => {
95- wait ( self , & ConnectionState :: Deactivated , self . dbus_manager . method_timeout ( ) )
96- } ,
99+ ConnectionState :: Deactivating => wait (
100+ self ,
101+ & ConnectionState :: Deactivated ,
102+ self . dbus_manager . method_timeout ( ) ,
103+ ) ,
97104 ConnectionState :: Unknown => Err ( "Unable to get connection state" . to_string ( ) ) ,
98105 _ => {
99106 let active_path_option =
@@ -102,7 +109,11 @@ impl Connection {
102109 if let Some ( active_path) = active_path_option {
103110 self . dbus_manager . deactivate_connection ( & active_path) ?;
104111
105- wait ( self , & ConnectionState :: Deactivated , self . dbus_manager . method_timeout ( ) )
112+ wait (
113+ self ,
114+ & ConnectionState :: Deactivated ,
115+ self . dbus_manager . method_timeout ( ) ,
116+ )
106117 } else {
107118 Ok ( ConnectionState :: Deactivated )
108119 }
@@ -143,7 +154,11 @@ impl Eq for Connection {}
143154
144155impl fmt:: Debug for Connection {
145156 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
146- write ! ( f, "Connection {{ path: {:?}, settings: {:?} }}" , self . path, self . settings)
157+ write ! (
158+ f,
159+ "Connection {{ path: {:?}, settings: {:?} }}" ,
160+ self . path, self . settings
161+ )
147162 }
148163}
149164
@@ -159,7 +174,6 @@ impl<'a> From<&'a Connection> for i32 {
159174 }
160175}
161176
162-
163177#[ derive( Default , Debug , Clone , Eq , PartialEq ) ]
164178pub struct ConnectionSettings {
165179 pub kind : String , // `type` is a reserved word, so we are using `kind` instead
@@ -194,7 +208,6 @@ impl From<i64> for ConnectionState {
194208 }
195209}
196210
197-
198211pub fn get_connections ( dbus_manager : & Rc < DBusNetworkManager > ) -> Result < Vec < Connection > , String > {
199212 let paths = dbus_manager. list_connections ( ) ?;
200213
@@ -209,7 +222,6 @@ pub fn get_connections(dbus_manager: &Rc<DBusNetworkManager>) -> Result<Vec<Conn
209222 Ok ( connections)
210223}
211224
212-
213225pub fn get_active_connections (
214226 dbus_manager : & Rc < DBusNetworkManager > ,
215227) -> Result < Vec < Connection > , String > {
@@ -228,7 +240,6 @@ pub fn get_active_connections(
228240 Ok ( connections)
229241}
230242
231-
232243pub fn connect_to_access_point < P > (
233244 dbus_manager : & Rc < DBusNetworkManager > ,
234245 device_path : & str ,
@@ -250,7 +261,11 @@ where
250261
251262 let connection = Connection :: init ( dbus_manager, & path) ?;
252263
253- let state = wait ( & connection, & ConnectionState :: Activated , dbus_manager. method_timeout ( ) ) ?;
264+ let state = wait (
265+ & connection,
266+ & ConnectionState :: Activated ,
267+ dbus_manager. method_timeout ( ) ,
268+ ) ?;
254269
255270 Ok ( ( connection, state) )
256271}
@@ -267,17 +282,15 @@ where
267282 S : AsSsidSlice + ?Sized ,
268283 P : AsAsciiStr + ?Sized ,
269284{
270- let ( path, _) = dbus_manager. create_hotspot (
271- device_path,
272- interface,
273- ssid,
274- password,
275- address,
276- ) ?;
285+ let ( path, _) = dbus_manager. create_hotspot ( device_path, interface, ssid, password, address) ?;
277286
278287 let connection = Connection :: init ( dbus_manager, & path) ?;
279288
280- let state = wait ( & connection, & ConnectionState :: Activated , dbus_manager. method_timeout ( ) ) ?;
289+ let state = wait (
290+ & connection,
291+ & ConnectionState :: Activated ,
292+ dbus_manager. method_timeout ( ) ,
293+ ) ?;
281294
282295 Ok ( ( connection, state) )
283296}
@@ -320,25 +333,24 @@ fn wait(
320333 total_time += 1 ;
321334
322335 if state == * target_state {
323- debug ! ( "Connection target state reached: {:?} / {}s elapsed" , state, total_time) ;
336+ debug ! (
337+ "Connection target state reached: {:?} / {}s elapsed" ,
338+ state, total_time
339+ ) ;
324340
325341 return Ok ( state) ;
326342 } else if total_time >= timeout {
327343 debug ! (
328344 "Timeout reached in waiting for connection state ({:?}): {:?} / {}s elapsed" ,
329- target_state,
330- state,
331- total_time
345+ target_state, state, total_time
332346 ) ;
333347
334348 return Ok ( state) ;
335349 }
336350
337351 debug ! (
338352 "Still waiting for connection state ({:?}): {:?} / {}s elapsed" ,
339- target_state,
340- state,
341- total_time
353+ target_state, state, total_time
342354 ) ;
343355 }
344356}
@@ -358,15 +370,16 @@ mod tests {
358370 // e.g. export TEST_WIFI_SSID="Resin.io Wifi"
359371 let wifi_env_var = "TEST_WIFI_SSID" ;
360372 let connection = match :: std:: env:: var ( wifi_env_var) {
361- Ok ( ssid) => {
362- connections
363- . iter ( )
364- . filter ( |c| c. settings ( ) . ssid . as_str ( ) . unwrap ( ) == ssid)
365- . nth ( 0 )
366- . unwrap ( )
367- . clone ( )
368- } ,
369- Err ( e) => panic ! ( "couldn't retrieve environment variable {}: {}" , wifi_env_var, e) ,
373+ Ok ( ssid) => connections
374+ . iter ( )
375+ . filter ( |c| c. settings ( ) . ssid . as_str ( ) . unwrap ( ) == ssid)
376+ . nth ( 0 )
377+ . unwrap ( )
378+ . clone ( ) ,
379+ Err ( e) => panic ! (
380+ "couldn't retrieve environment variable {}: {}" ,
381+ wifi_env_var, e
382+ ) ,
370383 } ;
371384
372385 let state = connection. get_state ( ) . unwrap ( ) ;
0 commit comments