@@ -282,6 +282,14 @@ impl SocketAddrV4 {
282
282
impl SocketAddrV6 {
283
283
/// Creates a new socket address from the ip/port/flowinfo/scope_id
284
284
/// components.
285
+ ///
286
+ /// # Examples
287
+ ///
288
+ /// ```
289
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
290
+ ///
291
+ /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
292
+ /// ```
285
293
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
286
294
pub fn new ( ip : Ipv6Addr , port : u16 , flowinfo : u32 , scope_id : u32 )
287
295
-> SocketAddrV6 {
@@ -298,6 +306,15 @@ impl SocketAddrV6 {
298
306
}
299
307
300
308
/// Returns the IP address associated with this socket address.
309
+ ///
310
+ /// # Examples
311
+ ///
312
+ /// ```
313
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
314
+ ///
315
+ /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
316
+ /// assert_eq!(socket.ip(), &Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
317
+ /// ```
301
318
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
302
319
pub fn ip ( & self ) -> & Ipv6Addr {
303
320
unsafe {
@@ -306,44 +323,111 @@ impl SocketAddrV6 {
306
323
}
307
324
308
325
/// Change the IP address associated with this socket address.
326
+ ///
327
+ /// # Examples
328
+ ///
329
+ /// ```
330
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
331
+ ///
332
+ /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
333
+ /// socket.set_ip(Ipv6Addr::new(76, 45, 0, 0, 0, 0, 0, 0));
334
+ /// assert_eq!(socket.ip(), &Ipv6Addr::new(76, 45, 0, 0, 0, 0, 0, 0));
335
+ /// ```
309
336
#[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
310
337
pub fn set_ip ( & mut self , new_ip : Ipv6Addr ) {
311
338
self . inner . sin6_addr = * new_ip. as_inner ( )
312
339
}
313
340
314
341
/// Returns the port number associated with this socket address.
342
+ ///
343
+ /// # Examples
344
+ ///
345
+ /// ```
346
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
347
+ ///
348
+ /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
349
+ /// assert_eq!(socket.port(), 8080);
350
+ /// ```
315
351
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
316
352
pub fn port ( & self ) -> u16 {
317
353
ntoh ( self . inner . sin6_port )
318
354
}
319
355
320
356
/// Change the port number associated with this socket address.
357
+ ///
358
+ /// # Examples
359
+ ///
360
+ /// ```
361
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
362
+ ///
363
+ /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
364
+ /// socket.set_port(4242);
365
+ /// assert_eq!(socket.port(), 4242);
366
+ /// ```
321
367
#[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
322
368
pub fn set_port ( & mut self , new_port : u16 ) {
323
369
self . inner . sin6_port = hton ( new_port) ;
324
370
}
325
371
326
372
/// Returns the flow information associated with this address,
327
373
/// corresponding to the `sin6_flowinfo` field in C.
374
+ ///
375
+ /// # Examples
376
+ ///
377
+ /// ```
378
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
379
+ ///
380
+ /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 10, 0);
381
+ /// assert_eq!(socket.flowinfo(), 10);
382
+ /// ```
328
383
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
329
384
pub fn flowinfo ( & self ) -> u32 {
330
385
self . inner . sin6_flowinfo
331
386
}
332
387
333
388
/// Change the flow information associated with this socket address.
389
+ ///
390
+ /// # Examples
391
+ ///
392
+ /// ```
393
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
394
+ ///
395
+ /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 10, 0);
396
+ /// socket.set_flowinfo(56);
397
+ /// assert_eq!(socket.flowinfo(), 56);
398
+ /// ```
334
399
#[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
335
400
pub fn set_flowinfo ( & mut self , new_flowinfo : u32 ) {
336
401
self . inner . sin6_flowinfo = new_flowinfo;
337
402
}
338
403
339
404
/// Returns the scope ID associated with this address,
340
405
/// corresponding to the `sin6_scope_id` field in C.
406
+ ///
407
+ /// # Examples
408
+ ///
409
+ /// ```
410
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
411
+ ///
412
+ /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 78);
413
+ /// assert_eq!(socket.scope_id(), 78);
414
+ /// ```
341
415
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
342
416
pub fn scope_id ( & self ) -> u32 {
343
417
self . inner . sin6_scope_id
344
418
}
345
419
346
420
/// Change the scope ID associated with this socket address.
421
+ ///
422
+ /// # Examples
423
+ ///
424
+ /// ```
425
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
426
+ ///
427
+ /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 78);
428
+ /// socket.set_scope_id(42);
429
+ /// assert_eq!(socket.scope_id(), 42);
430
+ /// ```
347
431
#[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
348
432
pub fn set_scope_id ( & mut self , new_scope_id : u32 ) {
349
433
self . inner . sin6_scope_id = new_scope_id;
0 commit comments