diff options
Diffstat (limited to 'src/codec.rs')
-rw-r--r-- | src/codec.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/codec.rs b/src/codec.rs index 03cdf15..8b38a9b 100644 --- a/src/codec.rs +++ b/src/codec.rs @@ -1,14 +1,26 @@ +/// Codecs enable the concealment of payload data inside the data of a carrier. pub trait Codec { + /// Data type representing the carrier. type Carrier; + + /// Data type representing the payload. type Payload; + + /// Data type representing encoder output/decoder input (usually the same as the carrier). type Output; + + /// Type of errors produced by this codec. type Error; - fn encode( - &self, - carrier: impl Into<Self::Carrier>, - payload: impl Into<Self::Payload>, - ) -> Result<Self::Output, Self::Error>; + /// Embeds payload data inside carrier, returning the result. + fn encode<C, P>(&self, carrier: C, payload: P) -> Result<Self::Output, Self::Error> + where + C: Into<Self::Carrier>, + P: Into<Self::Payload>; - fn decode(&self, encoded: impl Into<Self::Output>) -> Result<(Self::Carrier, Self::Payload), Self::Error>; + /// Extracts payload data from an encoded carrier, returning the carrier with data removed and the + /// payload data. + fn decode<E>(&self, encoded: E) -> Result<(Self::Carrier, Self::Payload), Self::Error> + where + E: Into<Self::Output>; } |