diff options
Diffstat (limited to 'src/wrapper.rs')
-rw-r--r-- | src/wrapper.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/wrapper.rs b/src/wrapper.rs index 0920ad4..992988c 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -2,16 +2,49 @@ use crate::cfb8::CipherError; use mcproto_rs::protocol::State; +/// +/// Indicates that a type provided by this crate is wrapping some inner value of type `I`, which can +/// be unwrapped by calling the `into_inner` function. +/// pub trait CraftWrapper<I> { + /// + /// Unwraps the wrapped value of type `I`, and drops the wrapper type + /// fn into_inner(self) -> I; } +/// +/// Trait for stateful connection types, such as the `CraftReader<R>` or `CraftWriter<W>` or combo +/// type `CraftConnection<R, W>`. +/// +/// Allows for control over protocol state, compression threshold, and encryption if those features +/// are enabled. +/// pub trait CraftIo { + /// + /// Changes the current connection state. For readers, this changes how numeric packet IDs are + /// interpreted. For writers, this will change the packets that can be written without a panic. + /// fn set_state(&mut self, next: State); + #[cfg(feature = "compression")] + /// + /// Modifies the compression configuration. If a value of `None` is provided, then compression is + /// disabled. If a value of `Some` is provided, then the threshold is set to that value. + /// + /// If a 0 or negative value is provided in a `Some` variant, then it is the same as calling + /// this function with the `None` variant + /// fn set_compression_threshold(&mut self, threshold: Option<i32>); #[cfg(feature = "encryption")] + /// + /// Modifies the encryption configuration. This function should only be called once, and can only + /// be used to enable encryption. + /// + /// If encryption is already enabled or the arguments are not valid for the cipher, then an + /// error is returned and nothing in the underlying state is changed. + /// fn enable_encryption(&mut self, key: &[u8], iv: &[u8]) -> Result<(), CipherError>; } |