pub trait Encoding {
// Required methods
fn encode(&self, i: &Instruction) -> String;
fn decode_instr(&self, text: &str) -> DecodeResult;
fn decode_cai(&self, text: &str) -> DecodeResult;
}Expand description
The Encoding trait defines all methods that an encoder/decoder must implement.
Required Methods§
Sourcefn encode(&self, i: &Instruction) -> String
fn encode(&self, i: &Instruction) -> String
Given an instruction, convert it to its string representation.
Sourcefn decode_instr(&self, text: &str) -> DecodeResult
fn decode_instr(&self, text: &str) -> DecodeResult
Given a string, try to convert it back to an instruction according to the implemented encoding.
§Errors
Decoding may fail.
- When the string violates the encoding, a DecodeResult::Err(String) value is returned. The string payload describes the decoding error.
- When the string is empty, it decodes to DecodeResult::None.
Sourcefn decode_cai(&self, text: &str) -> DecodeResult
fn decode_cai(&self, text: &str) -> DecodeResult
Given a string, try to convert it back to a “constant as instruction” according to the implemented encoding.
§Errors
Decoding may fail.
- When the string violates the encoding, a DecodeResult::Err(String) value is returned. The string payload describes the decoding error.
- When the string is empty, it decodes to DecodeResult::None.