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<I: DualStackIpExt, D: WeakDeviceIdentifier, BT: TcpBindingsTypes, P: TcpDemuxContext<I, D, BT>>
17    TcpDemuxContext<I, D, BT> for UninstantiableWrapper<P>
18{
19    type IpTransportCtx<'a> = P::IpTransportCtx<'a>;
20    fn with_demux<O, F: FnOnce(&DemuxState<I, D, BT>) -> O>(&mut self, _cb: F) -> O {
21        self.uninstantiable_unreachable()
22    }
23    fn with_demux_mut<O, F: FnOnce(&mut DemuxState<I, D, BT>) -> O>(&mut self, _cb: F) -> O {
24        self.uninstantiable_unreachable()
25    }
26}
27
28impl<P> AsThisStack<P> for UninstantiableWrapper<P> {
29    fn as_this_stack(&mut self) -> &mut P {
30        self.uninstantiable_unreachable()
31    }
32}
33
34impl<I: DualStackIpExt> DualStackDemuxIdConverter<I> for Uninstantiable {
35    fn convert<D: WeakDeviceIdentifier, BT: TcpBindingsTypes>(
36        &self,
37        _id: TcpSocketId<I, D, BT>,
38    ) -> <I::OtherVersion as DualStackBaseIpExt>::DemuxSocketId<D, BT> {
39        self.uninstantiable_unreachable()
40    }
41}
42
43impl<
44    I: DualStackIpExt,
45    D: WeakDeviceIdentifier,
46    BT: TcpBindingsTypes,
47    P: TcpDualStackContext<I::OtherVersion, D, BT>,
48> TcpDualStackContext<I, D, BT> for UninstantiableWrapper<P>
49{
50    type DualStackIpTransportCtx<'a> = P::DualStackIpTransportCtx<'a>;
51    fn other_demux_id_converter(&self) -> impl DualStackDemuxIdConverter<I> {
52        self.uninstantiable_unreachable::<Uninstantiable>()
53    }
54
55    fn dual_stack_enabled(&self, _ip_options: &I::DualStackIpOptions) -> bool {
56        self.uninstantiable_unreachable()
57    }
58
59    fn set_dual_stack_enabled(&self, _ip_options: &mut I::DualStackIpOptions, _value: bool) {
60        self.uninstantiable_unreachable()
61    }
62
63    fn with_both_demux_mut<
64        O,
65        F: FnOnce(&mut DemuxState<I, D, BT>, &mut DemuxState<I::OtherVersion, D, BT>) -> O,
66    >(
67        &mut self,
68        _cb: F,
69    ) -> O {
70        self.uninstantiable_unreachable()
71    }
72}