Neglect
parameterHow do we represent combinations of transmutation options?
Make Neglect
a const parameter:
unsafe trait AlwaysTransmuteFrom<Src, const NEGLECT: ???>
{ ... }
unsafe trait UnstableTransmuteFrom<Src, Scope, const NEGLECT: ???>
{ ... }
What do we replace "???
" with?
const NEGLECT: Neglect
Surface syntax:
fn example<Src, Dst>()
where
/* not neglecting any static checks */
Dst: AlwaysTransmuteFrom<Src, {Neglect::NOTHING}>,
/* neglecting just validity */
Dst: AlwaysTransmuteFrom<Src, {Neglect {validity: true, ..Neglect::NOTHING}}>,
/* neglecting validity and alignment */
Dst: AlwaysTransmuteFrom<Src, {Neglect {alignment: true, validity: true, ..Neglect::NOTHING}}>,
{}
Pros:
Cons:
NEGLECT
cannot be defaulted; common case of neglect nothing thus isn't syntactically freeconst NEGLECT: &'static [Neglect]
Surface syntax:
fn example<Src, Dst>()
where
/* not neglecting any static checks */
Dst: AlwaysTransmuteFrom<Src, {&[]}>,
/* neglecting just validity */
Dst: AlwaysTransmuteFrom<Src, {&[Neglect::Validity]}>,
/* neglecting validity and alignment */
Dst: AlwaysTransmuteFrom<Src, {&[Neglect::Validity, Neglect::Alignment]}>,
/* or, equivalently: */
Dst: AlwaysTransmuteFrom<Src, {&[Neglect::Alignment, Neglect::Validity]}>,
{}
Pros:
Cons:
NEGLECT
cannot be defaulted; common case of neglect nothing thus isn't syntactically free[Neglect::Validity, Neglect::Alignment]
and [Neglect::Alignment, Neglect::Validity]
are distinct types.unsafe trait AlwaysTransmuteFrom<Src, Neglect>
where
Neglect: TransmuteOptions
{ ... }
unsafe trait UnstableTransmuteFrom<Src, Neglect>
where
Neglect: TransmuteOptions
{ ... }
This time, we don't need to settle what the exact type of Neglect
ought to be.
(Option, ...)
Surface syntax:
fn example<Src, Dst>()
where
/* not neglecting any static checks */
Dst: AlwaysTransmuteFrom<Src>,
/* neglecting just validity */
Dst: AlwaysTransmuteFrom<Src, Neglect::Validity>,
/* neglecting validity and alignment */
Dst: AlwaysTransmuteFrom<Src, (Neglect::Validity, Neglect::Alignment)>,
/* or, equivalently: */
Dst: AlwaysTransmuteFrom<Src, (Neglect::Alignment, Neglect::Validity)>,
{}
Pros:
Neglect
can be defaulted; common case of neglect nothing therefore requires no additional typingNeglect
is instantiated.Cons:
(Neglect::Validity, Neglect::Alignment)
and (Neglect::Alignment, Neglect::Validity)
are distinct types.Option + Option
Surface syntax:
fn example<Src, Dst>()
where
/* not neglecting any static checks */
Dst: AlwaysTransmuteFrom<Src>,
/* neglecting just validity */
Dst: AlwaysTransmuteFrom<Src, NeglectValidity>,
/* neglecting validity and alignment */
Dst: AlwaysTransmuteFrom<Src, NeglectValidity + NeglectAlignment>,
{}
Pros:
Neglect
can be defaulted; common case of neglect nothing therefore requires no additional typingNeglect
is instantiated.Cons:
bare_trait_objects
are deprecated. could we squash that lint for these particular types?