MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / call_with_sockaddr

Function call_with_sockaddr

src/net/addr.rs:109–116  ·  view source on GitHub ↗

Helper for implementing `SocketAddrArg::with_sockaddr`. # Safety This calls `f` with a pointer to an object it has a reference to, with the and the length of that object, so they'll be valid for the duration of the call.

(
    addr: &A,
    f: impl FnOnce(*const SocketAddrOpaque, SocketAddrLen) -> R,
)

Source from the content-addressed store, hash-verified

107/// and the length of that object, so they'll be valid for the duration of the
108/// call.
109pub(crate) unsafe fn call_with_sockaddr<A, R>(
110 addr: &A,
111 f: impl FnOnce(*const SocketAddrOpaque, SocketAddrLen) -> R,
112) -> R {
113 let ptr = as_ptr(addr).cast();
114 let len = size_of::<A>() as SocketAddrLen;
115 f(ptr, len)
116}
117
118// SAFETY: This just forwards to the inner `SocketAddrArg` implementations.
119unsafe impl SocketAddrArg for SocketAddr {

Callers 2

with_sockaddrMethod · 0.85
with_sockaddrMethod · 0.85

Calls 2

as_ptrFunction · 0.85
fFunction · 0.85

Tested by

no test coverage detected