asn1_rs/asn1_types/
choice.rs

1use crate::{FromBer, FromDer, Tag, Tagged};
2
3pub trait Choice {
4    /// Is the provided [`Tag`] decodable as a variant of this `CHOICE`?
5    fn can_decode(tag: Tag) -> bool;
6}
7
8/// This blanket impl allows any [`Tagged`] type to function as a [`Choice`]
9/// with a single alternative.
10impl<T> Choice for T
11where
12    T: Tagged,
13{
14    fn can_decode(tag: Tag) -> bool {
15        T::TAG == tag
16    }
17}
18
19pub trait BerChoice<'a>: Choice + FromBer<'a> {}
20
21pub trait DerChoice<'a>: Choice + FromDer<'a> {}