Skip to main content

luaur_common/records/
first.rs

1//! Port of a `First<T, ...>` template metafunction whose member `using type = T`
2//! exposes the first type of a pack.
3//!
4//! **Deviation (documented):** C++'s `First<T>::type` is an inherent member type
5//! alias; Rust inherent associated types are unstable, so the `type` member is
6//! re-expressed as the stable associated type of the [`FirstType`] trait. The
7//! relationship `First<T> -> T` is preserved; access it as
8//! `<First<T> as FirstType>::Type`.
9
10#[allow(non_camel_case_types)]
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
12pub struct First<T> {
13    pub(crate) _marker: core::marker::PhantomData<T>,
14}
15
16/// Carries the `First<T>::type == T` relationship as a stable associated type.
17pub trait FirstType {
18    type Type;
19}
20
21impl<T> FirstType for First<T> {
22    type Type = T;
23}