pub enum ToplevelDefinition {
Type(ToplevelTypeDefinition),
Value(ToplevelValueDefinition),
Information(ToplevelInformationDefinition),
}
Expand description
Represents a top-level ASN.1 definition. The compiler distinguished three different variants of top-level definitions.
Type
definitions define custom types based on ASN.1’s built-in typesValue
definitions define values using custom ot built-in typesInformation
definitions define abstraction concepts introduced in ITU-T X.681
The linker and any [Backend] for this compiler consumes top-level definitions in order to generate bindings.
Variants§
Type(ToplevelTypeDefinition)
Value(ToplevelValueDefinition)
Information(ToplevelInformationDefinition)
Implementations§
source§impl ToplevelDefinition
impl ToplevelDefinition
sourcepub fn name(&self) -> &String
pub fn name(&self) -> &String
Returns the name of a top-level definition.
§Example
assert_eq!(
ToplevelDefinition::Value(
ToplevelValueDefinition {
comments: String::from("Comments from the ASN.1 spec"),
parameterization: None,
name: String::from("the-answer"),
associated_type: ASN1Type::Integer(Integer {
constraints: vec![],
distinguished_values: None,
}),
value: ASN1Value::Integer(42),
index: None,
}
).name(),
&String::from("the-answer")
);
source§impl ToplevelDefinition
impl ToplevelDefinition
pub fn is_class_with_name( &self, name: &String, ) -> Option<&InformationObjectClass>
sourcepub fn has_constraint_reference(&self) -> bool
pub fn has_constraint_reference(&self) -> bool
Traverses a top-level declaration to check for references to other top-level declarations
in a constraint. An example would be the constraint of the intercontinental
field in the
following example.
fifteen INTEGER = 15
Departures ::= SEQUENCE {
local SEQUENCE (SIZE(0..999)) OF Local,
continental SEQUENCE (SIZE(0..99)) OF Continental,
intercontinental SEQUENCE (SIZE(0..fifteen)) OF Intercontinental
}
sourcepub fn link_constraint_reference(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
) -> Result<bool, GrammarError>
pub fn link_constraint_reference( &mut self, tlds: &BTreeMap<String, ToplevelDefinition>, ) -> Result<bool, GrammarError>
Traverses a top-level declaration to replace references to other top-level declarations
in a constraint. An example would be the constraint of the intercontinental
field in the
following example.
fifteen INTEGER = 15
Departures ::= SEQUENCE {
local SEQUENCE (SIZE(0..999)) OF Local,
continental SEQUENCE (SIZE(0..99)) OF Continental,
intercontinental SEQUENCE (SIZE(0..fifteen)) OF Intercontinental
}
The method handles linking of multiple constraint references within a top-level declaration.
§Parameterization
This linking step also resolves implementations of parameterized types. The compiler does not create representations of abstract parameterized types but only of actual implementations. For example, no rust output will be generated for
ParamType { INTEGER: lower, BOOLEAN: flag } ::= SEQUENCE {
int-value INTEGER (lower..12),
bool-value BOOLEAN DEFAULT flag
}
but an implementing type such as
ImplType ::= ParamType { 2, TRUE }
will be represented in the generated rust bindings.
§Params
tlds
- vector of other top-level declarations that will be searched as the method resolves a reference returnstrue
if the reference was resolved successfully.
sourcepub fn mark_recursive(&mut self) -> Result<(), GrammarError>
pub fn mark_recursive(&mut self) -> Result<(), GrammarError>
Traverses top-level declarations and marks recursive types
sourcepub fn collect_supertypes(
&mut self,
tlds: &BTreeMap<String, ToplevelDefinition>,
) -> Result<(), GrammarError>
pub fn collect_supertypes( &mut self, tlds: &BTreeMap<String, ToplevelDefinition>, ) -> Result<(), GrammarError>
Collects supertypes of ASN1 values.
Trait Implementations§
source§impl Clone for ToplevelDefinition
impl Clone for ToplevelDefinition
source§fn clone(&self) -> ToplevelDefinition
fn clone(&self) -> ToplevelDefinition
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ToplevelDefinition
impl Debug for ToplevelDefinition
source§impl PartialEq for ToplevelDefinition
impl PartialEq for ToplevelDefinition
impl StructuralPartialEq for ToplevelDefinition
Auto Trait Implementations§
impl Freeze for ToplevelDefinition
impl !RefUnwindSafe for ToplevelDefinition
impl !Send for ToplevelDefinition
impl !Sync for ToplevelDefinition
impl Unpin for ToplevelDefinition
impl !UnwindSafe for ToplevelDefinition
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)