Skip to content

Commit

Permalink
Merge pull request #7 from v0-e/fix-literal-examples
Browse files Browse the repository at this point in the history
docs: Add module wrapper to ASN.1 literal usage examples
  • Loading branch information
6d7a authored Apr 5, 2024
2 parents 5e5adb5 + 605e6ab commit a481bb7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ fn main() {
// set an output path for the generated rust code
.set_output_path(PathBuf::from("./asn/generated.rs"))
// you may also compile literal ASN1 snippets
.add_asn_literal("My-test-integer ::= INTEGER (1..128)")
.add_asn_literal(format!(
"TestModule DEFINITIONS AUTOMATIC TAGS::= BEGIN {} END",
"My-test-integer ::= INTEGER (1..128)"
))
.compile() {
Ok(warnings /* Vec<Box<dyn Error>> */) => { /* handle compilation warnings */ }
Err(error /* Box<dyn Error> */) => { /* handle unrecoverable compilation error */ }
Expand Down
25 changes: 20 additions & 5 deletions rasn-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
//! // set an output path for the generated rust code
//! .set_output_path(PathBuf::from("./asn/generated.rs"))
//! // you may also compile literal ASN1 snippets
//! .add_asn_literal("My-test-integer ::= INTEGER (1..128)")
//! .add_asn_literal(format!(
//! "TestModule DEFINITIONS AUTOMATIC TAGS::= BEGIN {} END",
//! "My-test-integer ::= INTEGER (1..128)"
//! ))
//! .compile() {
//! Ok(warnings /* Vec<Box<dyn Error>> */) => { /* handle compilation warnings */ }
//! Err(error /* Box<dyn Error> */) => { /* handle unrecoverable compilation error */ }
Expand Down Expand Up @@ -235,7 +238,10 @@ impl<B: Backend> Compiler<B, CompilerMissingParams> {
/// * `literal` - literal ASN1 statement to include
/// ```rust
/// # use rasn_compiler::Compiler;
/// Compiler::new().add_asn_literal("My-test-integer ::= INTEGER (1..128)").compile_to_string();
/// Compiler::new().add_asn_literal(format!(
/// "TestModule DEFINITIONS AUTOMATIC TAGS::= BEGIN {} END",
/// "My-test-integer ::= INTEGER (1..128)"
/// )).compile_to_string();
/// ```
pub fn add_asn_literal(self, literal: impl Into<String>) -> Compiler<B, CompilerSourcesSet> {
Compiler {
Expand Down Expand Up @@ -298,7 +304,10 @@ impl<B: Backend> Compiler<B, CompilerOutputSet> {
/// * `literal` - literal ASN1 statement to include
/// ```rust
/// # use rasn_compiler::Compiler;
/// Compiler::new().add_asn_literal("My-test-integer ::= INTEGER (1..128)").compile_to_string();
/// Compiler::new().add_asn_literal(format!(
/// "TestModule DEFINITIONS AUTOMATIC TAGS::= BEGIN {} END",
/// "My-test-integer ::= INTEGER (1..128)"
/// )).compile_to_string();
/// ```
pub fn add_asn_literal(self, literal: impl Into<String>) -> Compiler<B, CompilerReady> {
Compiler {
Expand Down Expand Up @@ -344,7 +353,10 @@ impl<B: Backend> Compiler<B, CompilerSourcesSet> {
/// * `literal` - literal ASN1 statement to include
/// ```rust
/// # use rasn_compiler::Compiler;
/// Compiler::new().add_asn_literal("My-test-integer ::= INTEGER (1..128)").compile_to_string();
/// Compiler::new().add_asn_literal(format!(
/// "TestModule DEFINITIONS AUTOMATIC TAGS::= BEGIN {} END",
/// "My-test-integer ::= INTEGER (1..128)"
/// )).compile_to_string();
/// ```
pub fn add_asn_literal(self, literal: impl Into<String>) -> Compiler<B, CompilerSourcesSet> {
let mut sources: Vec<AsnSource> = self.state.sources;
Expand Down Expand Up @@ -470,7 +482,10 @@ impl<B: Backend> Compiler<B, CompilerReady> {
/// * `literal` - literal ASN1 statement to include
/// ```rust
/// # use rasn_compiler::Compiler;
/// Compiler::new().add_asn_literal("My-test-integer ::= INTEGER (1..128)").compile_to_string();
/// Compiler::new().add_asn_literal(format!(
/// "TestModule DEFINITIONS AUTOMATIC TAGS::= BEGIN {} END",
/// "My-test-integer ::= INTEGER (1..128)"
/// )).compile_to_string();
/// ```
pub fn add_asn_literal(self, literal: impl Into<String>) -> Compiler<B, CompilerReady> {
let mut sources: Vec<AsnSource> = self.state.sources;
Expand Down

0 comments on commit a481bb7

Please sign in to comment.