You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We currently use the impl_string_type! macro to write the bodies of various ASN.1 string types.
For each ASN.1 type, we support an owned (*String) and borrowed (*StringRef) type.
Instead I think we could potentially have two generic types, e.g. StringType and StringRefType.
We need to make them generic around a value (the tag) though, so this seems like a use case for const generics. Unfortunately we model Tag as an enum, which we can't use as a const generic parameter until the adt_const_params feature is stabilized. However, this enum is repr(u8), so it's possible to use e.g. const TAG: u8 as the const generic parameter, casting/converting the Tag into a u8 (temporarily until adt_const_params are stabilized).
Really the various string types differ in two respects:
The tag, which is captured as a const generic parameter per above
Validation rules, i.e. what characters are allowed in the constructor
To capture these concerns I propose making a trait which can be impl'd for a const generic StringType/StringTypeRef containing these validation rules.
Then the existing types can become type aliases, e.g. pub type Ia5String = StringType<Tag::Ia5String as u8>
The text was updated successfully, but these errors were encountered:
We currently use the
impl_string_type!
macro to write the bodies of various ASN.1 string types.For each ASN.1 type, we support an owned (
*String
) and borrowed (*StringRef
) type.Instead I think we could potentially have two generic types, e.g.
StringType
andStringRefType
.We need to make them generic around a value (the tag) though, so this seems like a use case for const generics. Unfortunately we model
Tag
as anenum
, which we can't use as a const generic parameter until theadt_const_params
feature is stabilized. However, this enum isrepr(u8)
, so it's possible to use e.g.const TAG: u8
as the const generic parameter, casting/converting theTag
into au8
(temporarily untiladt_const_params
are stabilized).Really the various string types differ in two respects:
To capture these concerns I propose making a trait which can be impl'd for a const generic
StringType
/StringTypeRef
containing these validation rules.Then the existing types can become type aliases, e.g.
pub type Ia5String = StringType<Tag::Ia5String as u8>
The text was updated successfully, but these errors were encountered: