librasn / compiler

An ASN1 compiler producing Rust bindings for the rasn framework
Other
13 stars 7 forks source link

Generate From impls for CHOICE #34

Closed shahn closed 1 month ago

shahn commented 1 month ago

The format I am working with uses CHOICE quite a bit and it would be nice to be able to go from the inner type to the container. Perhaps a From impl for this could be auto-generated? I would be happy to take a stab at it, if it is deemed acceptable.

6d7a commented 1 month ago

Sounds good! We should add this to the compiler config, though. The generated bindings are quite large already now, so any code generation beyond the bare minimum should be optional. Just to make sure I understand your use case:

MessageType ::= CHOICE {
                  text                     OCTET STRING,
                  codedNumeric  INTEGER
}

would generate

// ...

impl From<OctetString> for MessageType {
    // ...
}

impl From<Integer> for MessageType {
    // ...
}

Thank you for the suggestion, I'd be happy to review a PR.

shahn commented 1 month ago

Yes, the idea is exactly what you described. I will work on a PR and come back, might be a little while.