@@ -282,6 +282,14 @@ impl SocketAddrV4 {
282282impl SocketAddrV6 {
283283 /// Creates a new socket address from the ip/port/flowinfo/scope_id
284284 /// 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+ /// ```
285293 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
286294 pub fn new ( ip : Ipv6Addr , port : u16 , flowinfo : u32 , scope_id : u32 )
287295 -> SocketAddrV6 {
@@ -298,6 +306,15 @@ impl SocketAddrV6 {
298306 }
299307
300308 /// 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+ /// ```
301318 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
302319 pub fn ip ( & self ) -> & Ipv6Addr {
303320 unsafe {
@@ -306,44 +323,111 @@ impl SocketAddrV6 {
306323 }
307324
308325 /// 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+ /// ```
309336 #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
310337 pub fn set_ip ( & mut self , new_ip : Ipv6Addr ) {
311338 self . inner . sin6_addr = * new_ip. as_inner ( )
312339 }
313340
314341 /// 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+ /// ```
315351 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
316352 pub fn port ( & self ) -> u16 {
317353 ntoh ( self . inner . sin6_port )
318354 }
319355
320356 /// 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+ /// ```
321367 #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
322368 pub fn set_port ( & mut self , new_port : u16 ) {
323369 self . inner . sin6_port = hton ( new_port) ;
324370 }
325371
326372 /// Returns the flow information associated with this address,
327373 /// 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+ /// ```
328383 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
329384 pub fn flowinfo ( & self ) -> u32 {
330385 self . inner . sin6_flowinfo
331386 }
332387
333388 /// 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+ /// ```
334399 #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
335400 pub fn set_flowinfo ( & mut self , new_flowinfo : u32 ) {
336401 self . inner . sin6_flowinfo = new_flowinfo;
337402 }
338403
339404 /// Returns the scope ID associated with this address,
340405 /// 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+ /// ```
341415 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
342416 pub fn scope_id ( & self ) -> u32 {
343417 self . inner . sin6_scope_id
344418 }
345419
346420 /// 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+ /// ```
347431 #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
348432 pub fn set_scope_id ( & mut self , new_scope_id : u32 ) {
349433 self . inner . sin6_scope_id = new_scope_id;
0 commit comments