pub trait Encoder {
// Required method
fn encode(&self, input: &str) -> String;
}Expand description
A trait for encoding transforms.
Implement this trait to create custom encoders that can be used with the attackstr encoding system.
§Thread Safety
This trait does not require Send or Sync. Thread-safety depends on the
concrete implementing type.
§Example
use attackstr::Encoder;
struct Rot13Encoder;
impl Encoder for Rot13Encoder {
fn encode(&self, input: &str) -> String {
input.chars().map(|c| match c {
'a'..='m' | 'A'..='M' => (c as u8 + 13) as char,
'n'..='z' | 'N'..='Z' => (c as u8 - 13) as char,
_ => c,
}).collect()
}
}
let encoder = Rot13Encoder;
assert_eq!(encoder.encode("hello"), "uryyb");Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".