File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,23 @@ 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 core::mem::size_of;
58
+ /// use libc::sockaddr_storage;
59
+ /// use socket2::{SockAddr, SockAddrStorage, socklen_t};
60
+ ///
61
+ /// fn from_sockaddr_storage(recv_address: &sockaddr_storage) -> SockAddr {
62
+ /// let mut storage = SockAddrStorage::zeroed();
63
+ /// let libc_address = unsafe { storage.view_as::<sockaddr_storage>() };
64
+ /// *libc_address = *recv_address;
65
+ /// unsafe { SockAddr::new(storage, size_of::<sockaddr_storage>() as socklen_t) }
66
+ /// }
67
+ /// # }
68
+ /// ```
52
69
#[ inline]
53
70
pub unsafe fn view_as < T > ( & mut self ) -> & mut T {
54
71
assert ! ( size_of:: <T >( ) <= size_of:: <Self >( ) ) ;
You can’t perform that action at this time.
0 commit comments