netstack3_tcp/
uninstantiable.rs

1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Groups trait implementations for uninstantiable types.
6
7use explicit::UnreachableExt as _;
8
9use netstack3_base::{Uninstantiable, UninstantiableWrapper, WeakDeviceIdentifier};
10
11use crate::internal::socket::{
12    AsThisStack, DemuxState, DualStackBaseIpExt, DualStackDemuxIdConverter, DualStackIpExt,
13    TcpBindingsTypes, TcpDemuxContext, TcpDualStackContext, TcpSocketId,
14};
15
16impl<
17        I: DualStackIpExt,
18        D: WeakDeviceIdentifier,
19        BT: TcpBindingsTypes,
20        P: TcpDemuxContext<I, D, BT>,
21    > TcpDemuxContext<I, D, BT> for UninstantiableWrapper<P>
22{
23    type IpTransportCtx<'a> = P::IpTransportCtx<'a>;
24    fn with_demux<O, F: FnOnce(&DemuxState<I, D, BT>) -> O>(&mut self, _cb: F) -> O {
25        self.uninstantiable_unreachable()
26    }
27    fn with_demux_mut<O, F: FnOnce(&mut DemuxState<I, D, BT>) -> O>(&mut self, _cb: F) -> O {
28        self.uninstantiable_unreachable()
29    }
30}
31
32impl<P> AsThisStack<P> for UninstantiableWrapper<P> {
33    fn as_this_stack(&mut self) -> &mut P {
34        self.uninstantiable_unreachable()
35    }
36}
37
38impl<I: DualStackIpExt> DualStackDemuxIdConverter<I> for Uninstantiable {
39    fn convert<D: WeakDeviceIdentifier, BT: TcpBindingsTypes>(
40        &self,
41        _id: TcpSocketId<I, D, BT>,
42    ) -> <I::OtherVersion as DualStackBaseIpExt>::DemuxSocketId<D, BT> {
43        self.uninstantiable_unreachable()
44    }
45}
46
47impl<
48        I: DualStackIpExt,
49        D: WeakDeviceIdentifier,
50        BT: TcpBindingsTypes,
51        P: TcpDualStackContext<I::OtherVersion, D, BT>,
52    > TcpDualStackContext<I, D, BT> for UninstantiableWrapper<P>
53{
54    type DualStackIpTransportCtx<'a> = P::DualStackIpTransportCtx<'a>;
55    fn other_demux_id_converter(&self) -> impl DualStackDemuxIdConverter<I> {
56        self.uninstantiable_unreachable::<Uninstantiable>()
57    }
58
59    fn dual_stack_enabled(&self, _ip_options: &I::DualStackIpOptions) -> bool {
60        self.uninstantiable_unreachable()
61    }
62
63    fn set_dual_stack_enabled(&self, _ip_options: &mut I::DualStackIpOptions, _value: bool) {
64        self.uninstantiable_unreachable()
65    }
66
67    fn with_both_demux_mut<
68        O,
69        F: FnOnce(&mut DemuxState<I, D, BT>, &mut DemuxState<I::OtherVersion, D, BT>) -> O,
70    >(
71        &mut self,
72        _cb: F,
73    ) -> O {
74        self.uninstantiable_unreachable()
75    }
76}