File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,22 @@ impl SockAddrStorage {
49
49
/// # Safety
50
50
///
51
51
/// The type `T` must be one of the `sockaddr_*` types defined by this platform.
52
+ ///
53
+ /// # Examples
54
+ /// ```
55
+ /// # #[allow(dead_code)]
56
+ /// # #[cfg(unix)] mod unix_example {
57
+ /// use libc::sockaddr_storage;
58
+ /// use socket2::{SockAddr, SockAddrStorage, socklen_t};
59
+ ///
60
+ /// fn from_sockaddr_storage(recv_address: &sockaddr_storage) -> SockAddr {
61
+ /// let mut storage = SockAddrStorage::zeroed();
62
+ /// let libc_address = unsafe { storage.view_as::<sockaddr_storage>() };
63
+ /// *libc_address = *recv_address;
64
+ /// unsafe { SockAddr::new(storage, size_of::<sockaddr_storage>() as socklen_t) }
65
+ /// }
66
+ /// # }
67
+ /// ```
52
68
#[ inline]
53
69
pub unsafe fn view_as < T > ( & mut self ) -> & mut T {
54
70
assert ! ( size_of:: <T >( ) <= size_of:: <Self >( ) ) ;
You can’t perform that action at this time.
0 commit comments