base_scheduler/address_info_collection.rs
1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use crate::AddressInfoView;
5
6/// An owned resolver result whose representation is chosen by the backend. Borrowed entry views remain valid only while the result is borrowed. Iteration must preserve candidate ordering, duplicates, and native socket parameters without requiring a copied collection or per-entry reference counts.
7///
8/// Native implementations can traverse an owned `addrinfo` list directly and free it once through the matching native deallocator on drop. Validation may inspect that list without materializing portable records. Concrete result types may expose additional native accessors. Arrays, vectors, and shared cached storage can provide the same portable accessors without native layouts.
9///
10/// ```compile_fail
11/// use base_scheduler::{AddressInfo, AddressInfoCollection, AddressInfoView, SocketType};
12/// let entry = {
13/// let result = [AddressInfo { address: "127.0.0.1:80".parse().unwrap(), socket_type: SocketType::Stream, protocol: None }];
14/// result.entries().next().unwrap()
15/// };
16/// let address = entry.address(); // A borrowed entry cannot outlive its owner.
17/// ```
18pub trait AddressInfoCollection: Send + Sync + 'static {
19 /// Iterate borrowed entry views in resolver order, preserving duplicates. The views cannot outlive this collection.
20 fn entries(&self) -> impl Iterator<Item: AddressInfoView + Send> + Send;
21}
22
23impl<T: AddressInfoView + Send + Sync + 'static> AddressInfoCollection for Vec<T> {
24 fn entries(&self) -> impl Iterator<Item: AddressInfoView + Send> + Send {
25 self.as_slice().iter()
26 }
27}
28
29impl<T: AddressInfoView + Send + Sync + 'static, const N: usize> AddressInfoCollection for [T; N] {
30 fn entries(&self) -> impl Iterator<Item: AddressInfoView + Send> + Send {
31 self.as_slice().iter()
32 }
33}
34
35impl<T: AddressInfoView + Send + Sync + 'static> AddressInfoCollection for Box<[T]> {
36 fn entries(&self) -> impl Iterator<Item: AddressInfoView + Send> + Send {
37 self.as_ref().iter()
38 }
39}