11extern  crate  coap; 
22
3+ use  coap:: CoAPClient ; 
34use  std:: io; 
45use  std:: io:: ErrorKind ; 
5- use  coap:: CoAPClient ; 
66
77fn  main ( )  { 
88    println ! ( "GET url:" ) ; 
@@ -21,20 +21,21 @@ fn main() {
2121    example_observe ( ) ; 
2222} 
2323
24- 
2524fn  example_get ( )  { 
2625    let  url = "coap://127.0.0.1:5683/hello/get" ; 
2726    println ! ( "Client request: {}" ,  url) ; 
2827
2928    match  CoAPClient :: get ( url)  { 
3029        Ok ( response)  => { 
31-             println ! ( "Server reply: {}" , 
32-                      String :: from_utf8( response. message. payload) . unwrap( ) ) ; 
30+             println ! ( 
31+                 "Server reply: {}" , 
32+                 String :: from_utf8( response. message. payload) . unwrap( ) 
33+             ) ; 
3334        } 
3435        Err ( e)  => { 
3536            match  e. kind ( )  { 
36-                 ErrorKind :: WouldBlock  => println ! ( "Request timeout" ) ,     // Unix 
37-                 ErrorKind :: TimedOut  => println ! ( "Request timeout" ) ,       // Windows 
37+                 ErrorKind :: WouldBlock  => println ! ( "Request timeout" ) ,  // Unix 
38+                 ErrorKind :: TimedOut  => println ! ( "Request timeout" ) ,    // Windows 
3839                _ => println ! ( "Request error: {:?}" ,  e) , 
3940            } 
4041        } 
@@ -48,13 +49,15 @@ fn example_post() {
4849
4950    match  CoAPClient :: post ( url,  data)  { 
5051        Ok ( response)  => { 
51-             println ! ( "Server reply: {}" , 
52-                      String :: from_utf8( response. message. payload) . unwrap( ) ) ; 
52+             println ! ( 
53+                 "Server reply: {}" , 
54+                 String :: from_utf8( response. message. payload) . unwrap( ) 
55+             ) ; 
5356        } 
5457        Err ( e)  => { 
5558            match  e. kind ( )  { 
56-                 ErrorKind :: WouldBlock  => println ! ( "Request timeout" ) ,     // Unix 
57-                 ErrorKind :: TimedOut  => println ! ( "Request timeout" ) ,       // Windows 
59+                 ErrorKind :: WouldBlock  => println ! ( "Request timeout" ) ,  // Unix 
60+                 ErrorKind :: TimedOut  => println ! ( "Request timeout" ) ,    // Windows 
5861                _ => println ! ( "Request error: {:?}" ,  e) , 
5962            } 
6063        } 
@@ -68,13 +71,15 @@ fn example_put() {
6871
6972    match  CoAPClient :: put ( url,  data)  { 
7073        Ok ( response)  => { 
71-             println ! ( "Server reply: {}" , 
72-                      String :: from_utf8( response. message. payload) . unwrap( ) ) ; 
74+             println ! ( 
75+                 "Server reply: {}" , 
76+                 String :: from_utf8( response. message. payload) . unwrap( ) 
77+             ) ; 
7378        } 
7479        Err ( e)  => { 
7580            match  e. kind ( )  { 
76-                 ErrorKind :: WouldBlock  => println ! ( "Request timeout" ) ,     // Unix 
77-                 ErrorKind :: TimedOut  => println ! ( "Request timeout" ) ,       // Windows 
81+                 ErrorKind :: WouldBlock  => println ! ( "Request timeout" ) ,  // Unix 
82+                 ErrorKind :: TimedOut  => println ! ( "Request timeout" ) ,    // Windows 
7883                _ => println ! ( "Request error: {:?}" ,  e) , 
7984            } 
8085        } 
@@ -87,13 +92,15 @@ fn example_delete() {
8792
8893    match  CoAPClient :: delete ( url)  { 
8994        Ok ( response)  => { 
90-             println ! ( "Server reply: {}" , 
91-                      String :: from_utf8( response. message. payload) . unwrap( ) ) ; 
95+             println ! ( 
96+                 "Server reply: {}" , 
97+                 String :: from_utf8( response. message. payload) . unwrap( ) 
98+             ) ; 
9299        } 
93100        Err ( e)  => { 
94101            match  e. kind ( )  { 
95-                 ErrorKind :: WouldBlock  => println ! ( "Request timeout" ) ,     // Unix 
96-                 ErrorKind :: TimedOut  => println ! ( "Request timeout" ) ,       // Windows 
102+                 ErrorKind :: WouldBlock  => println ! ( "Request timeout" ) ,  // Unix 
103+                 ErrorKind :: TimedOut  => println ! ( "Request timeout" ) ,    // Windows 
97104                _ => println ! ( "Request error: {:?}" ,  e) , 
98105            } 
99106        } 
@@ -102,11 +109,16 @@ fn example_delete() {
102109
103110fn  example_observe ( )  { 
104111    let  mut  client = CoAPClient :: new ( "127.0.0.1:5683" ) . unwrap ( ) ; 
105-     client. observe ( "/hello/put" ,  |msg| { 
106-         println ! ( "resource changed {}" ,  String :: from_utf8( msg. payload) . unwrap( ) ) ; 
107-     } ) . unwrap ( ) ; 
112+     client
113+         . observe ( "/hello/put" ,  |msg| { 
114+             println ! ( 
115+                 "resource changed {}" , 
116+                 String :: from_utf8( msg. payload) . unwrap( ) 
117+             ) ; 
118+         } ) 
119+         . unwrap ( ) ; 
108120
109121    println ! ( "Press any key to stop..." ) ; 
110122
111123    io:: stdin ( ) . read_line ( & mut  String :: new ( ) ) . unwrap ( ) ; 
112- } 
124+ } 
0 commit comments