base_scheduler/address_info_view.rs
1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use crate::{AddressInfo, SocketAddress, SocketProtocol, SocketType};
5
6/// Portable accessors for a resolved IP endpoint and its socket creation parameters. A view may borrow a native resolver entry; accessing one field need not copy or normalize the others.
7pub trait AddressInfoView {
8 /// Decode the IP endpoint on demand, preserving IPv6 flow information and scope identifiers.
9 fn address(&self) -> SocketAddress;
10
11 /// The socket type for creating a socket to this endpoint.
12 fn socket_type(&self) -> SocketType;
13
14 /// `None` represents the resolver's zero/default protocol.
15 fn protocol(&self) -> Option<SocketProtocol>;
16
17 /// Explicitly materialize a small, owned portable record. This conversion requires no heap allocation.
18 fn to_address_info(&self) -> AddressInfo {
19 AddressInfo {
20 address: self.address(),
21 socket_type: self.socket_type(),
22 protocol: self.protocol(),
23 }
24 }
25}
26
27impl<T: AddressInfoView + ?Sized> AddressInfoView for &T {
28 fn address(&self) -> SocketAddress {
29 T::address(self)
30 }
31
32 fn socket_type(&self) -> SocketType {
33 T::socket_type(self)
34 }
35
36 fn protocol(&self) -> Option<SocketProtocol> {
37 T::protocol(self)
38 }
39}