Skip to main content

base_scheduler/
socket_address_view.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use crate::SocketAddress;
5
6/// An IP endpoint exposed by an address representation chosen by its provider. A view can borrow native metadata or refer to an already materialized portable address. The contract specifies the endpoint, without prescribing storage, copying, or allocation costs.
7pub trait SocketAddressView: Send + Sync {
8    /// Materialize the portable endpoint, preserving IPv6 flow information and scope identifiers.
9    fn to_socket_address(&self) -> SocketAddress;
10}
11
12impl SocketAddressView for SocketAddress {
13    fn to_socket_address(&self) -> SocketAddress {
14        *self
15    }
16}
17
18impl<T: SocketAddressView + ?Sized> SocketAddressView for &T {
19    fn to_socket_address(&self) -> SocketAddress {
20        T::to_socket_address(self)
21    }
22}