@@ -236,6 +236,14 @@ impl SocketAddrV4 {
236
236
impl SocketAddrV6 {
237
237
/// Creates a new socket address from the ip/port/flowinfo/scope_id
238
238
/// components.
239
+ ///
240
+ /// # Examples
241
+ ///
242
+ /// ```
243
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
244
+ ///
245
+ /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
246
+ /// ```
239
247
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
240
248
pub fn new ( ip : Ipv6Addr , port : u16 , flowinfo : u32 , scope_id : u32 )
241
249
-> SocketAddrV6 {
@@ -252,6 +260,15 @@ impl SocketAddrV6 {
252
260
}
253
261
254
262
/// Returns the IP address associated with this socket address.
263
+ ///
264
+ /// # Examples
265
+ ///
266
+ /// ```
267
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
268
+ ///
269
+ /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
270
+ /// assert_eq!(socket.ip(), &Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
271
+ /// ```
255
272
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
256
273
pub fn ip ( & self ) -> & Ipv6Addr {
257
274
unsafe {
@@ -260,44 +277,111 @@ impl SocketAddrV6 {
260
277
}
261
278
262
279
/// Change the IP address associated with this socket address.
280
+ ///
281
+ /// # Examples
282
+ ///
283
+ /// ```
284
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
285
+ ///
286
+ /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
287
+ /// socket.set_ip(Ipv6Addr::new(76, 45, 0, 0, 0, 0, 0, 0));
288
+ /// assert_eq!(socket.ip(), &Ipv6Addr::new(76, 45, 0, 0, 0, 0, 0, 0));
289
+ /// ```
263
290
#[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
264
291
pub fn set_ip ( & mut self , new_ip : Ipv6Addr ) {
265
292
self . inner . sin6_addr = * new_ip. as_inner ( )
266
293
}
267
294
268
295
/// Returns the port number associated with this socket address.
296
+ ///
297
+ /// # Examples
298
+ ///
299
+ /// ```
300
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
301
+ ///
302
+ /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
303
+ /// assert_eq!(socket.port(), 8080);
304
+ /// ```
269
305
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
270
306
pub fn port ( & self ) -> u16 {
271
307
ntoh ( self . inner . sin6_port )
272
308
}
273
309
274
310
/// Change the port number associated with this socket address.
311
+ ///
312
+ /// # Examples
313
+ ///
314
+ /// ```
315
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
316
+ ///
317
+ /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
318
+ /// socket.set_port(4242);
319
+ /// assert_eq!(socket.port(), 4242);
320
+ /// ```
275
321
#[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
276
322
pub fn set_port ( & mut self , new_port : u16 ) {
277
323
self . inner . sin6_port = hton ( new_port) ;
278
324
}
279
325
280
326
/// Returns the flow information associated with this address,
281
327
/// corresponding to the `sin6_flowinfo` field in C.
328
+ ///
329
+ /// # Examples
330
+ ///
331
+ /// ```
332
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
333
+ ///
334
+ /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 10, 0);
335
+ /// assert_eq!(socket.flowinfo(), 10);
336
+ /// ```
282
337
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
283
338
pub fn flowinfo ( & self ) -> u32 {
284
339
self . inner . sin6_flowinfo
285
340
}
286
341
287
342
/// Change the flow information associated with this socket address.
343
+ ///
344
+ /// # Examples
345
+ ///
346
+ /// ```
347
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
348
+ ///
349
+ /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 10, 0);
350
+ /// socket.set_flowinfo(56);
351
+ /// assert_eq!(socket.flowinfo(), 56);
352
+ /// ```
288
353
#[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
289
354
pub fn set_flowinfo ( & mut self , new_flowinfo : u32 ) {
290
355
self . inner . sin6_flowinfo = new_flowinfo;
291
356
}
292
357
293
358
/// Returns the scope ID associated with this address,
294
359
/// corresponding to the `sin6_scope_id` field in C.
360
+ ///
361
+ /// # Examples
362
+ ///
363
+ /// ```
364
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
365
+ ///
366
+ /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 78);
367
+ /// assert_eq!(socket.scope_id(), 78);
368
+ /// ```
295
369
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
296
370
pub fn scope_id ( & self ) -> u32 {
297
371
self . inner . sin6_scope_id
298
372
}
299
373
300
374
/// Change the scope ID associated with this socket address.
375
+ ///
376
+ /// # Examples
377
+ ///
378
+ /// ```
379
+ /// use std::net::{SocketAddrV6, Ipv6Addr};
380
+ ///
381
+ /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 78);
382
+ /// socket.set_scope_id(42);
383
+ /// assert_eq!(socket.scope_id(), 42);
384
+ /// ```
301
385
#[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
302
386
pub fn set_scope_id ( & mut self , new_scope_id : u32 ) {
303
387
self . inner . sin6_scope_id = new_scope_id;
0 commit comments