netstack3_base/
uninstantiable.rsuse core::convert::Infallible as Never;
use core::marker::PhantomData;
use explicit::UnreachableExt as _;
use crate::{
BidirectionalConverter, CoreTimerContext, CounterContext, Device, DeviceIdContext,
TimerBindingsTypes,
};
#[derive(Clone, Copy)]
pub struct Uninstantiable(Never);
impl AsRef<Never> for Uninstantiable {
fn as_ref(&self) -> &Never {
&self.0
}
}
impl<I, O> BidirectionalConverter<I, O> for Uninstantiable {
fn convert_back(&self, _: O) -> I {
self.uninstantiable_unreachable()
}
fn convert(&self, _: I) -> O {
self.uninstantiable_unreachable()
}
}
pub struct UninstantiableWrapper<A>(Never, PhantomData<A>);
impl<A> AsRef<Never> for UninstantiableWrapper<A> {
fn as_ref(&self) -> &Never {
let Self(never, _marker) = self;
&never
}
}
impl<T, BT, C> CoreTimerContext<T, BT> for UninstantiableWrapper<C>
where
BT: TimerBindingsTypes,
C: CoreTimerContext<T, BT>,
{
fn convert_timer(dispatch_id: T) -> BT::DispatchId {
C::convert_timer(dispatch_id)
}
}
impl<P, C> CounterContext<C> for UninstantiableWrapper<P> {
fn with_counters<O, F: FnOnce(&C) -> O>(&self, _cb: F) -> O {
self.uninstantiable_unreachable()
}
}
impl<D: Device, C: DeviceIdContext<D>> DeviceIdContext<D> for UninstantiableWrapper<C> {
type DeviceId = C::DeviceId;
type WeakDeviceId = C::WeakDeviceId;
}
impl<A: Iterator> Iterator for UninstantiableWrapper<A> {
type Item = A::Item;
fn next(&mut self) -> Option<Self::Item> {
self.uninstantiable_unreachable()
}
}