### Minimal demo: feed bytes and print parsed events (examples/basic.rs) Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html Example from examples/basic.rs (line 6) showing how to create a Parser, receive bytes, and iterate over TelnetEvents. It also demonstrates sending a GMCP payload via subnegotiation_text. ```rust fn main() { // Minimal demo: feed a few bytes and print parsed events let mut parser = Parser::new(); // Pretend this came from the network: "hi", doubled IAC, CRLF let events = parser.receive(b"hi \xFF\xFF\r\n"); for ev in events { match ev { TelnetEvents::DataReceive(buf) => { println!("DATA : {:?}", String::from_utf8_lossy(&buf)); } TelnetEvents::Negotiation(n) => { println!("NEG : cmd={} opt={}", n.command, n.option); } TelnetEvents::Subnegotiation(s) => { println!("SUB : opt={} len={}", s.option, s.buffer.len()); } TelnetEvents::IAC(i) => { println!("IAC : cmd={}", i.command); } TelnetEvents::DecompressImmediate(b) => { println!("MCCP : boundary len={}", b.len()); } TelnetEvents::DataSend(buf) => { // Bytes that should be written to the socket as-is println!("SEND : {} bytes", buf.len()); } _ => {} } } // Example: send a GMCP payload (application would write buf to the socket) if let Some(TelnetEvents::DataSend(buf)) = parser.subnegotiation_text(op_option::GMCP, "{\"Core.Ping\":1}") { println!("SEND : {} bytes (GMCP)", buf.len()); } } ``` -------------------------------- ### Quickstart: Parse Telnet bytes and send text Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/index.html Shows basic usage of Parser::new(), receive(), and send_text(). The receive() call returns a Vec that you match on, including DataReceive, Negotiation, and Subnegotiation. send_text() escapes IAC bytes automatically. ```rust use libmudtelnet_rs::{Parser, events::TelnetEvents}; let mut parser = Parser::new(); let events = parser.receive(b"hello \xff\xff world\r\n"); for ev in events { match ev { TelnetEvents::DataReceive(buf) => { // Application text/data from the server let _bytes = &buf[..]; } TelnetEvents::Negotiation(n) => { // WILL/WONT/DO/DONT notifications (state is tracked internally) let _cmd = n.command; let _opt = n.option; } TelnetEvents::Subnegotiation(sub) => { // Protocol payload (e.g., GMCP/MSDP) let _which = sub.option; let _payload = &sub.buffer[..]; } TelnetEvents::IAC(_) | TelnetEvents::DataSend(_) | TelnetEvents::DecompressImmediate(_) => {} _ => {} } } // Sending text (IAC bytes escaped for you): let _send = parser.send_text("look\r\n"); ``` -------------------------------- ### Typical usage: declare GMCP support and send WILL Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/index.html?search= Shows how to create a CompatibilityTable, set an option as supported locally and remotely, and use the parser to send a WILL command. The example is a doctest and includes a dummy use of WILL to avoid an unused import warning. ```rust use libmudtelnet_rs::{Parser, compatibility::{CompatibilityEntry, CompatibilityTable}}; use libmudtelnet_rs::telnet::op_option::GMCP; use libmudtelnet_rs::telnet::op_command::WILL; // Declare that we support GMCP locally and remotely, initially disabled. let mut table = CompatibilityTable::new(); table.set_option(GMCP, CompatibilityEntry::new(true, true, false, false)); let mut parser = Parser::with_support(table); // Ask to enable GMCP locally (IAC WILL GMCP) if let Some(send) = parser._will(GMCP) { let _bytes_to_socket = send.to_bytes(); } // When the server responds (e.g., DO GMCP), the parser tracks state for you. let _ = WILL; // avoid unused import in doctest ``` -------------------------------- ### Module compatibility Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Documentation for the compatibility module, including structs and a usage example. ```APIDOC ## Module compatibility ### Description Negotiation support and state table. The parser uses a compact 256-entry table to record, for each Telnet option, whether it is supported locally and remotely, and whether either direction is currently enabled. ### Structs #### CompatibilityEntry - **Description**: An expansion of a bitmask contained in `CompatibilityTable`. #### CompatibilityTable - **Description**: A table of options that are supported locally or remotely, and their current state. ### Usage Example ```rust use libmudtelnet_rs::{Parser, compatibility::{CompatibilityEntry, CompatibilityTable}}; use libmudtelnet_rs::telnet::op_option::GMCP; // Declare that we support GMCP locally and remotely, initially disabled. let mut table = CompatibilityTable::new(); table.set_option(GMCP, CompatibilityEntry::new(true, true, false, false)); let mut parser = Parser::with_support(table); // Ask to enable GMCP locally (IAC WILL GMCP) if let Some(send) = parser._will(GMCP) { let _bytes_to_socket = send.to_bytes(); } ``` Note: Call `CompatibilityTable::reset_states` when reconnecting, to clear any enabled flags while preserving which options you support. ``` -------------------------------- ### Minimal Parser::new() demo from examples/basic.rs Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search= Feeds a few bytes into a new Parser and prints parsed events. The example data is "hi", a doubled IAC, and CRLF, as if it came from the network. ```rust fn main() { // Minimal demo: feed a few bytes and print parsed events let mut parser = Parser::new(); // Pretend this came from the network: "hi", doubled IAC, CRLF let events = parser.receive(b"hi \xFF\xFF\r\n"); for ev in events { match ev { _ => println!("{:?}", ev), } } } ``` -------------------------------- ### Escape IAC bytes example Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html Example showing how to use Parser::escape_iac to double IAC bytes in data to be transmitted. The example uses a vector containing IAC and asserts the output equals the doubled sequence. ```rust use libmudtelnet_rs::Parser; use libmudtelnet_rs::telnet::op_command::IAC; let out = Parser::escape_iac(vec![IAC, 1, 6, 2]); assert_eq!(&out[..], [IAC, IAC, 1, 6, 2]); ``` -------------------------------- ### CompatibilityTable::set_option Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/struct.CompatibilityTable.html?search= Sets an option value by getting the bitmask from a CompatibilityEntry. ```APIDOC ## CompatibilityTable::set_option ### Description Sets an option value by getting the bitmask from a CompatibilityEntry. ### Method set_option ### Signature pub fn set_option(&mut self, option: u8, entry: CompatibilityEntry) ### Parameters - **option** (u8) - Required - The option code to set. - **entry** (CompatibilityEntry) - Required - The CompatibilityEntry containing the bitmask value to set. ``` -------------------------------- ### Convert TelnetEvents::IAC to bytes with to_bytes Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/events/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Converts a TelnetEvents::IAC event back to its raw byte representation. The example creates an IAC NOP event, calls to_bytes(), and asserts the result equals the two-byte sequence [IAC, NOP]. Use this when you need to serialize an IAC command for sending over the socket. ```rust use libmudtelnet_rs::events::{TelnetEvents, TelnetIAC}; use libmudtelnet_rs::telnet::op_command::{IAC, NOP}; let ev = TelnetEvents::IAC(TelnetIAC::new(NOP)); let bytes = ev.to_bytes(); assert_eq!(&bytes[..], [IAC, NOP]); ``` -------------------------------- ### CompatibilityTable::new Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/index.html?search=u32+-%3E+bool Creates a new CompatibilityTable instance. ```APIDOC ## CompatibilityTable::new ### Description Creates a new CompatibilityTable instance. ### Method new ### Signature `pub fn new() -> CompatibilityTable` ### Parameters None ### Returns - **CompatibilityTable** - A new table with default support and state. ### Example ```rust let mut table = CompatibilityTable::new(); ``` ``` -------------------------------- ### CompatibilityEntry::new Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/index.html?search=u32+-%3E+bool Creates a new CompatibilityEntry with specified local/remote support and enabled states. ```APIDOC ## CompatibilityEntry::new ### Description Creates a new CompatibilityEntry with specified local/remote support and enabled states. ### Method new ### Signature `pub fn new(local_supported: bool, remote_supported: bool, local_enabled: bool, remote_enabled: bool) -> CompatibilityEntry` ### Parameters - **local_supported** (bool) - Required - Whether the option is supported locally (us→them). - **remote_supported** (bool) - Required - Whether the option is supported remotely (them→us). - **local_enabled** (bool) - Required - Whether the local direction is currently enabled. - **remote_enabled** (bool) - Required - Whether the remote direction is currently enabled. ### Returns - **CompatibilityEntry** - The new compatibility entry. ### Example ```rust let entry = CompatibilityEntry::new(true, true, false, false); ``` ``` -------------------------------- ### Minimal Parser demo in examples/basic.rs Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Minimal demo that feeds a few bytes into a new Parser and prints parsed events. The comment notes the bytes pretend to come from the network. ```rust fn main() { // Minimal demo: feed a few bytes and print parsed events let mut parser = Parser::new(); // Pretend this came from the network: "hi", doubled IAC, ... } ``` -------------------------------- ### CompatibilityTable::new Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/index.html?search= Creates a new compatibility table with default support and state for all Telnet options. ```APIDOC ## CompatibilityTable::new ### Description Creates a new compatibility table with default support and state for all Telnet options. ### Method Constructor ### Signature `pub fn new() -> CompatibilityTable` ### Parameters None ### Returns - **CompatibilityTable** - A new table with all options unsupported and disabled. ### Example ```rust use libmudtelnet_rs::compatibility::CompatibilityTable; let table = CompatibilityTable::new(); ``` ``` -------------------------------- ### unescape_iac example: reverse escaped IAC bytes Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html Shows how to call Parser::unescape_iac with a vector containing an escaped IAC byte. The function reverses escaped IAC bytes for non-IAC sequences and data, turning [255, 255, 1, 6, 2] into [255, 1, 6, 2]. ```rust use libmudtelnet_rs::Parser; use libmudtelnet_rs::telnet::op_command::IAC; let out = Parser::unescape_iac(vec![IAC, IAC, 1, 6, 2]); assert_eq!(&out[..], [IAC, 1, 6, 2]); ``` -------------------------------- ### Parser::with_support_and_capacity Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html Creates a parser with a specified buffer capacity and a provided CompatibilityTable. ```APIDOC ## Parser::with_support_and_capacity ### Description Creates a parser, setting the initial internal buffer capacity and directly supplying a `CompatibilityTable`. ### Method `pub fn with_support_and_capacity(size: usize, table: CompatibilityTable) -> Self` ### Parameters - `size` (usize) - Required - The initial capacity of the internal buffer. - `table` (CompatibilityTable) - Required - The compatibility table to configure the parser. ### Returns - `Self` - A new Parser instance with the specified buffer capacity and compatibility table. ``` -------------------------------- ### CompatibilityTable::from_options Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/struct.CompatibilityTable.html Creates a compatibility table with some option values set. ```APIDOC ## CompatibilityTable::from_options ### Description Creates a compatibility table with some option values set. ### Method from_options ### Signature pub fn from_options(values: &[(u8, u8)]) -> Self ### Parameters - `values` (slice of `(u8, u8)` tuples) - Required - A slice of `(u8, u8)` tuples. The first value is the option code, and the second is the bitmask value for that option. ### Notes An option bitmask can be generated using the `CompatibilityEntry` struct, using `entry.into_u8()`. ### Returns A new `CompatibilityTable` with the specified option values set. ``` -------------------------------- ### Quick reference for Telnet command and option constants Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/telnet/index.html Imports the op_command and op_option modules and asserts the values of IAC, WILL, and GMCP constants. ```rust use libmudtelnet_rs::telnet::op_command as cmd; use libmudtelnet_rs::telnet::op_option as opt; assert_eq!(cmd::IAC, 255); assert_eq!(cmd::WILL, 251); assert_eq!(opt::GMCP, 201); ``` -------------------------------- ### Parser::with_support Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html Creates a parser with a provided CompatibilityTable, using the default buffer capacity of 128 bytes. ```APIDOC ## Parser::with_support ### Description Creates a parser, directly supplying a `CompatibilityTable`. Uses the default initial buffer capacity of 128 bytes. ### Method `pub fn with_support(table: CompatibilityTable) -> Self` ### Parameters - `table` (CompatibilityTable) - Required - The compatibility table to configure the parser. ### Returns - `Self` - A new Parser instance with the given compatibility table. ``` -------------------------------- ### _do(&mut self, option: u8) -> Option Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search= Send a DO negotiation to enable an option remotely. ```APIDOC ## _do(&mut self, option: u8) -> Option ### Description Indicate to the other side that you would like them to utilize an option. ### Method _do ### Endpoint _do(&mut self, option: u8) -> Option ### Parameters - **option** (u8) - Required - The telnet option code you want to enable remotely. ### Returns - **Option** - A `DataSend` event to be processed, or None if the option is not supported or already enabled. ### Notes This method will do nothing if the option is not supported remotely via the `CompatibilityTable`. ``` -------------------------------- ### TelnetNegotiation::new Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/events/struct.TelnetNegotiation.html Creates a new TelnetNegotiation instance with the given command and option bytes. ```APIDOC ## TelnetNegotiation::new ### Description Creates a new `TelnetNegotiation` instance with the given command and option bytes. ### Method `pub fn new(command: u8, option: u8) -> Self` ### Parameters - **command** (u8) - Required - The Telnet command byte for the negotiation. - **option** (u8) - Required - The Telnet option byte for the negotiation. ### Returns - **TelnetNegotiation** - A new `TelnetNegotiation` instance. ``` -------------------------------- ### CompatibilityEntry::from Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/struct.CompatibilityEntry.html?search=std%3A%3Avec Expands a u8 bitmask into a CompatibilityEntry. ```APIDOC ## CompatibilityEntry::from ### Description Expands a u8 bitmask into a `CompatibilityEntry`. ### Method Static method ### Parameters - `value` (u8) - Required - The bitmask to expand. ### Returns A `CompatibilityEntry` instance. ``` -------------------------------- ### Create a default Parser with Parser::new Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a default, empty Parser with an internal buffer capacity of 128 bytes. Use this constructor before feeding bytes to the parser. ```rust pub fn new() -> Self ``` -------------------------------- ### CompatibilityTable::from_options Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/struct.CompatibilityTable.html?search= Creates a CompatibilityTable with some option values set from a slice of (u8, u8) tuples. ```APIDOC ## CompatibilityTable::from_options ### Description Creates a CompatibilityTable with some option values set from a slice of (u8, u8) tuples. ### Method from_options ### Signature pub fn from_options(values: &[(u8, u8)]) -> Self ### Parameters - **values** (&[(u8, u8)]) - Required - A slice of tuples where the first value is the option code and the second is the bitmask value for that option. ### Notes An option bitmask can be generated using the `CompatibilityEntry` struct, using `entry.into_u8()`. ### Returns - **Self** - A new CompatibilityTable with the specified options set. ``` -------------------------------- ### _do Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search=std%3A%3Avec Indicates to the other side that you would like them to utilize an option. Returns an Option event or None if the option is not supported or already enabled. ```APIDOC ## _do ### Description Indicates to the other side that you would like them to utilize an option. ### Method _do ### Signature pub fn _do(&mut self, option: u8) -> Option ### Parameters - **option** (u8) - Required - The telnet option code that you want to enable remotely. ### Returns - **Option** - A DataSend event to be processed, or None if the option is not supported or already enabled. ### Notes This method will do nothing if the option is not "supported" remotely via the `CompatibilityTable`. ``` -------------------------------- ### CompatibilityTable::support_local Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/struct.CompatibilityTable.html?search= Enables local support for an option. ```APIDOC ## CompatibilityTable::support_local ### Description Enables local support for an option. ### Method support_local ### Signature pub fn support_local(&mut self, option: u8) ### Parameters - **option** (u8) - Required - The option code to enable local support for. ``` -------------------------------- ### TelnetSubnegotiation::new Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/events/struct.TelnetSubnegotiation.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new TelnetSubnegotiation instance with the given option byte and buffer. ```APIDOC ## TelnetSubnegotiation::new ### Description Creates a new `TelnetSubnegotiation` instance with the specified option and buffer. ### Method `pub fn new(option: u8, buffer: Bytes) -> Self` ### Parameters - **option** (u8) - Required - The Telnet option code for this subnegotiation. - **buffer** (Bytes) - Required - The data buffer associated with the subnegotiation. ### Returns - **Self** - A new `TelnetSubnegotiation` instance. ``` ```APIDOC ## to_bytes ### Description Converts the `TelnetSubnegotiation` into its byte representation. ### Method pub fn to_bytes(self) -> Bytes ### Parameters - **self** - The TelnetSubnegotiation instance to convert. ### Returns - **Bytes** - The serialized byte representation of the subnegotiation. ``` ```APIDOC ## into_bytes ### Description Converts the `TelnetSubnegotiation` into bytes. Deprecated since 0.2.1; use `to_bytes` instead. ### Method pub fn into_bytes(self) -> Bytes ### Deprecation Deprecated since 0.2.1: Use `to_bytes` instead. ``` -------------------------------- ### CompatibilityEntry::into_u8 Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/struct.CompatibilityEntry.html?search=std%3A%3Avec Creates a u8 bitmask from this entry. ```APIDOC ## CompatibilityEntry::into_u8 ### Description Creates a u8 bitmask from this entry. ### Method Method ### Parameters - `self` - The CompatibilityEntry instance. ### Returns A `u8` bitmask representing the entry. ``` -------------------------------- ### TelnetIAC::new Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/events/struct.TelnetIAC.html Creates a new TelnetIAC instance with the given command byte. ```APIDOC ## TelnetIAC::new ### Description Creates a new `TelnetIAC` instance with the given command byte. ### Method `pub fn new(command: u8) -> Self` ### Parameters - `command` (u8) - Required - The command byte for the IAC sequence. ### Returns - `Self` - A new `TelnetIAC` instance. ``` -------------------------------- ### negotiate(&mut self, command: u8, option: u8) -> TelnetEvents Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search= Negotiate a telnet option with the remote end. ```APIDOC ## negotiate(&mut self, command: u8, option: u8) -> TelnetEvents ### Description Negotiate a telnet option with the remote end. ### Method negotiate ### Endpoint negotiate(&mut self, command: u8, option: u8) -> TelnetEvents ### Parameters - **command** (u8) - Required - The telnet command code to negotiate (e.g., WILL (251), WONT (252), DO (253), DONT (254)). - **option** (u8) - Required - The telnet option code being negotiated. ### Returns - **TelnetEvents::DataSend** - A `DataSend` event to be processed. ### Usage This method generates a `TelnetEvents::Send(DataEvent)` event containing a buffer that should be sent directly to the remote end, already properly encoded. ``` -------------------------------- ### Parser::new Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html Creates a default, empty Parser with an internal buffer capacity of 128 bytes. ```APIDOC ## Parser::new ### Description Creates a default, empty Parser with an internal buffer capacity of 128 bytes. ### Method `pub fn new() -> Self` ### Parameters None. ### Returns - `Self` - A new Parser instance. ### Example ```rust let mut parser = Parser::new(); ``` ``` -------------------------------- ### CompatibilityTable::support Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/struct.CompatibilityTable.html?search= Enables both remote and local support for an option. ```APIDOC ## CompatibilityTable::support ### Description Enables both remote and local support for an option. ### Method support ### Signature pub fn support(&mut self, option: u8) ### Parameters - **option** (u8) - Required - The option code to enable both local and remote support for. ``` -------------------------------- ### Typical usage: configure compatibility table and send IAC WILL GMCP Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/index.html?search=u32+-%3E+bool Sets up a CompatibilityTable declaring GMCP supported locally and remotely (initially disabled), then uses Parser::_will to emit an IAC WILL GMCP request. The parser tracks the server response (e.g., DO GMCP) and updates state automatically. ```rust use libmudtelnet_rs::{Parser, compatibility::{CompatibilityEntry, CompatibilityTable}}; use libmudtelnet_rs::telnet::op_option::GMCP; use libmudtelnet_rs::telnet::op_command::WILL; // Declare that we support GMCP locally and remotely, initially disabled. let mut table = CompatibilityTable::new(); table.set_option(GMCP, CompatibilityEntry::new(true, true, false, false)); let mut parser = Parser::with_support(table); // Ask to enable GMCP locally (IAC WILL GMCP) if let Some(send) = parser._will(GMCP) { let _bytes_to_socket = send.to_bytes(); } // When the server responds (e.g., DO GMCP), the parser tracks state for you. ``` -------------------------------- ### _will(&mut self, option: u8) -> Option Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search= Send a WILL negotiation to enable an option locally. ```APIDOC ## _will(&mut self, option: u8) -> Option ### Description Indicate to the other side that you are able and wanting to utilize an option. ### Method _will ### Endpoint _will(&mut self, option: u8) -> Option ### Parameters - **option** (u8) - Required - The telnet option code you want to enable locally. ### Returns - **Option** - The `DataSend` event to be processed, or None if not supported. ### Notes This method will do nothing if the option is not supported locally via the `CompatibilityTable`. ``` -------------------------------- ### MCCP2 Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/telnet/op_option/constant.MCCP2.html Documentation for the MCCP2 constant in the libmudtelnet-rs crate. ```APIDOC ## Constant `MCCP2` ### Description A constant representing the MCCP2 option code (86) used in the Telnet protocol. ### Value `86` (u8) ### Usage This constant is used to identify the MCCP2 option in Telnet option negotiation. ``` -------------------------------- ### _will Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search=std%3A%3Avec Indicates to the other side that you are able and wanting to utilize an option. Returns an Option event or None if not supported. ```APIDOC ## _will ### Description Indicates to the other side that you are able and wanting to utilize an option. ### Method _will ### Signature pub fn _will(&mut self, option: u8) -> Option ### Parameters - **option** (u8) - Required - The telnet option code that you want to enable locally. ### Returns - **Option** - The DataSend event to be processed, or None if not supported. ### Notes This method will do nothing if the option is not "supported" locally via the `CompatibilityTable`. ``` -------------------------------- ### Parser::with_capacity Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html Creates an empty parser with a specified initial internal buffer capacity. ```APIDOC ## Parser::with_capacity ### Description Creates an empty parser, setting the initial internal buffer capacity. ### Method `pub fn with_capacity(size: usize) -> Self` ### Parameters - `size` (usize) - Required - The initial capacity of the internal buffer. ### Returns - `Self` - A new Parser instance with the specified buffer capacity. ``` -------------------------------- ### vbytes! Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/macro.vbytes.html?search= Macro for calling Bytes::copy_from_slice(). Deprecated since 0.2.1: Use Bytes::copy_from_slice directly instead. ```APIDOC ## vbytes! ### Description Macro for calling `Bytes::copy_from_slice()`. ### Deprecation Deprecated since 0.2.1: Use `Bytes::copy_from_slice` directly instead. ### Syntax ```rust macro_rules! vbytes { ($slice:expr) => { ... }; } ``` ### Parameters - `$slice` (expression) - The slice expression to copy from. ### Usage This macro is used to create a `Bytes` value by copying from a slice. ### Example ```rust let bytes = vbytes!(&[1, 2, 3]); ``` ``` -------------------------------- ### vbytes! Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/macro.vbytes.html?search=std%3A%3Avec Macro for calling Bytes::copy_from_slice(). Deprecated since 0.2.1, use Bytes::copy_from_slice directly instead. ```APIDOC ## vbytes! ### Description Macro for calling `Bytes::copy_from_slice()`. Deprecated since 0.2.1: Use `Bytes::copy_from_slice` directly instead. ### Syntax ```rust macro_rules! vbytes { ($slice:expr) => { ... }; } ``` ### Parameters - `$slice` (expression) - The slice expression to copy from. ### Deprecation Deprecated since 0.2.1. Use `Bytes::copy_from_slice` directly instead. ``` -------------------------------- ### CompatibilityTable::support_remote Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/struct.CompatibilityTable.html?search= Enables remote support for an option. ```APIDOC ## CompatibilityTable::support_remote ### Description Enables remote support for an option. ### Method support_remote ### Signature pub fn support_remote(&mut self, option: u8) ### Parameters - **option** (u8) - Required - The option code to enable remote support for. ``` -------------------------------- ### subnegotiation(&mut self, option: u8, data: T) -> Option Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search= Send a subnegotiation for a locally supported option. ```APIDOC ## subnegotiation(&mut self, option: u8, data: T) -> Option ### Description Send a subnegotiation for a locally supported option. ### Method subnegotiation ### Endpoint subnegotiation(&mut self, option: u8, data: T) -> Option ### Parameters - **option** (u8) - Required - The telnet option code for the negotiation. - **data** (T) - Required - The data to be sent in the subnegotiation. Must implement `Into`. All IAC (255) byte values will be escaped. ### Returns - **Option** - A `DataSend` event to be processed, or None if the option is not supported or is currently disabled. ### Notes This method will do nothing if the option is not supported/enabled. For most options, the client must be the performer (local + `local_state`). For GMCP/MSDP specifically, the parser also allows sending when the remote side has enabled the option (remote + `remote_state`), reflecting the de‑facto bidirectional semantics after a `WILL/DO` handshake. ``` -------------------------------- ### NAOFFD Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/telnet/op_option/constant.NAOFFD.html Documentation for the NAOFFD constant in the libmudtelnet-rs crate. ```APIDOC ## Constant NAOFFD ### Description Represents the Telnet option code for NAOFFD (Negotiate About Output Forwarding Disable). ### Value `pub const NAOFFD: u8 = 13;` ### Type `u8` ### Usage This constant is used to identify the NAOFFD Telnet option in option negotiation. ``` -------------------------------- ### CompatibilityTable::get_option Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/struct.CompatibilityTable.html?search= Retrieves a CompatibilityEntry generated from the current state of the option value. ```APIDOC ## CompatibilityTable::get_option ### Description Retrieves a CompatibilityEntry generated from the current state of the option value. ### Method get_option ### Signature pub fn get_option(&self, option: u8) -> CompatibilityEntry ### Parameters - **option** (u8) - Required - The option code to retrieve. ### Returns - **CompatibilityEntry** - The current state of the option as a CompatibilityEntry. ``` -------------------------------- ### negotiate Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search=std%3A%3Avec Negotiates a telnet option with the given command and option codes. Returns a TelnetEvents::DataSend event to be processed. ```APIDOC ## negotiate ### Description Negotiates a telnet option with the given command and option codes. ### Method negotiate ### Signature pub fn negotiate(&mut self, command: u8, option: u8) -> TelnetEvents ### Parameters - **command** (u8) - Required - The telnet command code to be negotiated with. Example: WILL (251), WONT (252), DO (253), DONT (254) - **option** (u8) - Required - The telnet option code that is being negotiated. ### Returns - **TelnetEvents::DataSend** - A DataSend event to be processed. ### Usage This and other methods meant for sending data to the remote end will generate a `TelnetEvents::Send(DataEvent)` event. These Send events contain a buffer that should be sent directly to the remote end, as it will have already been encoded properly. ``` -------------------------------- ### _wont(&mut self, option: u8) -> Option Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search= Send a WONT negotiation to disable an option locally. ```APIDOC ## _wont(&mut self, option: u8) -> Option ### Description Indicate to the other side that you are not wanting to utilize an option. ### Method _wont ### Endpoint _wont(&mut self, option: u8) -> Option ### Parameters - **option** (u8) - Required - The telnet option code you want to disable locally. ### Returns - **Option** - A `DataSend` event to be processed, or None if the option is already disabled. ``` -------------------------------- ### pub fn subnegotiation_text(&mut self, option: u8, text: &str) -> Option Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Sends a subnegotiation for a locally supported option, using a string instead of raw byte values. Returns a DataSend event to be processed, or None if the option is not supported or is currently disabled. ```APIDOC ## pub fn subnegotiation_text(&mut self, option: u8, text: &str) -> Option ### Description Sends a subnegotiation for a locally supported option, using a string instead of raw byte values. The text will have all IAC (255) byte values escaped. ### Method Function call ### Signature `pub fn subnegotiation_text(&mut self, option: u8, text: &str) -> Option` ### Parameters - **option** (u8) - Required - A `u8` representing the telnet option code for the negotiation. - **text** (&str) - Required - A `&str` representing the text to be sent in the subnegotiation. This data will have all IAC (255) byte values escaped. ### Returns `Option` - A `DataSend` event to be processed, or None if the option is not supported or is currently disabled. ### Notes This method will do nothing if the option is not "supported" locally via the `CompatibilityTable`. ### Example ```rust if let Some(TelnetEvents::DataSend(buf)) = parser.subnegotiation_text(op_option::GMCP, "{\"Core.Ping\":1}") { println!("SEND : {} bytes (GMCP)", buf.len()); } ``` ``` -------------------------------- ### into_bytes Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/events/struct.TelnetSubnegotiation.html?search=std%3A%3Avec Converts the TelnetSubnegotiation into Bytes. Deprecated since 0.2.1; use `to_bytes` instead. ```APIDOC ## into_bytes ### Description Converts the TelnetSubnegotiation into Bytes. Deprecated since 0.2.1; use `to_bytes` instead. ### Method into_bytes ### Parameters #### Self Parameters - **self** - Required - The TelnetSubnegotiation instance to convert ### Returns - **Bytes** - The subnegotiation data as bytes ``` -------------------------------- ### _dont(&mut self, option: u8) -> Option Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search= Send a DONT negotiation to disable an option remotely. ```APIDOC ## _dont(&mut self, option: u8) -> Option ### Description Indicate to the other side that you would like them to stop utilizing an option. ### Method _dont ### Endpoint _dont(&mut self, option: u8) -> Option ### Parameters - **option** (u8) - Required - The telnet option code you want to disable remotely. ### Returns - **Option** - A `DataSend` event to be processed, or None if the option is already disabled. ``` -------------------------------- ### Compatibility Module API Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/index.html?search=std%3A%3Avec Code snippets for the compatibility module of libmudtelnet-rs, covering the CompatibilityTable and CompatibilityEntry types and the Parser methods used for Telnet option negotiation. ```APIDOC ## CompatibilityTable::new ### Description Creates a new, empty compatibility table for Telnet option negotiation support. ### Method Constructor ### Signature `pub fn new() -> CompatibilityTable` ### Parameters None ### Returns - **CompatibilityTable** - A new table with no options set. ### Example ```rust use libmudtelnet_rs::compatibility::CompatibilityTable; let table = CompatibilityTable::new(); ``` ``` ```APIDOC ## CompatibilityTable::set_option ### Description Sets the support and state for a given Telnet option in the table. ### Method Method ### Signature `pub fn set_option(&mut self, option: u8, entry: CompatibilityEntry)` ### Parameters - **option** (u8) - Required - The Telnet option code to configure. - **entry** (CompatibilityEntry) - Required - The compatibility entry specifying local/remote support and enabled states. ### Returns - **()** - No return value. ### Example ```rust use libmudtelnet_rs::compatibility::{CompatibilityTable, CompatibilityEntry}; use libmudtelnet_rs::telnet::op_option::GMCP; let mut table = CompatibilityTable::new(); table.set_option(GMCP, CompatibilityEntry::new(true, true, false, false)); ``` ``` ```APIDOC ## CompatibilityTable::reset_states ### Description Resets the enabled flags for all options while preserving which options are supported. ### Method Method ### Signature `pub fn reset_states(&mut self)` ### Parameters None ### Returns - **()** - No return value. ### Example ```rust use libmudtelnet_rs::compatibility::CompatibilityTable; let mut table = CompatibilityTable::new(); table.reset_states(); ``` ``` ```APIDOC ## CompatibilityEntry::new ### Description Creates a new compatibility entry with the given local/remote support and enabled states. ### Method Constructor ### Signature `pub fn new(local_supported: bool, remote_supported: bool, local_enabled: bool, remote_enabled: bool) -> CompatibilityEntry` ### Parameters - **local_supported** (bool) - Required - Whether the option is supported locally (us→them). - **remote_supported** (bool) - Required - Whether the option is supported remotely (them→us). - **local_enabled** (bool) - Required - Whether the local direction is currently enabled. - **remote_enabled** (bool) - Required - Whether the remote direction is currently enabled. ### Returns - **CompatibilityEntry** - A new entry with the specified support and state. ### Example ```rust use libmudtelnet_rs::compatibility::CompatibilityEntry; let entry = CompatibilityEntry::new(true, true, false, false); ``` ``` ```APIDOC ## Parser::with_support ### Description Creates a parser with the given compatibility table for Telnet option negotiation. ### Method Constructor ### Signature `pub fn with_support(table: CompatibilityTable) -> Parser` ### Parameters - **table** (CompatibilityTable) - Required - The compatibility table to use for option negotiation. ### Returns - **Parser** - A new parser instance configured with the given support table. ### Example ```rust use libmudtelnet_rs::{Parser, compatibility::{CompatibilityTable, CompatibilityEntry}}; use libmudtelnet_rs::telnet::op_option::GMCP; let mut table = CompatibilityTable::new(); table.set_option(GMCP, CompatibilityEntry::new(true, true, false, false)); let parser = Parser::with_support(table); ``` ``` ```APIDOC ## Parser::_will ### Description Requests to enable a Telnet option locally by sending IAC WILL. ### Method Method ### Signature `pub fn _will(&mut self, option: u8) -> Option` ### Parameters - **option** (u8) - Required - The Telnet option code to enable. ### Returns - **Option** - A sendable object containing the bytes to write to the socket, or `None` if the request cannot be made. ### Example ```rust use libmudtelnet_rs::{Parser, compatibility::{CompatibilityTable, CompatibilityEntry}}; use libmudtelnet_rs::telnet::op_option::GMCP; let mut table = CompatibilityTable::new(); table.set_option(GMCP, CompatibilityEntry::new(true, true, false, false)); let mut parser = Parser::with_support(table); if let Some(send) = parser._will(GMCP) { let _bytes_to_socket = send.to_bytes(); } ``` ``` -------------------------------- ### Parser Struct Methods Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/struct.Parser.html?search=std%3A%3Avec Documentation for the Parser struct and its public methods. ```APIDOC ## Parser::new ### Description Creates a default, empty Parser with an internal buffer capacity of 128 bytes. ### Method new ### Signature pub fn new() -> Self ### Parameters None ### Returns Self - A new Parser instance. ### Example ```rust let mut parser = Parser::new(); ``` ``` ```APIDOC ## Parser::with_capacity ### Description Creates an empty parser, setting the initial internal buffer capacity. ### Method with_capacity ### Signature pub fn with_capacity(size: usize) -> Self ### Parameters - **size** (usize) - Required - The initial internal buffer capacity. ### Returns Self - A new Parser instance with the specified buffer capacity. ### Example ```rust let parser = Parser::with_capacity(256); ``` ``` ```APIDOC ## Parser::with_support ### Description Creates a parser, directly supplying a CompatibilityTable. Uses the default initial buffer capacity of 128 bytes. ### Method with_support ### Signature pub fn with_support(table: CompatibilityTable) -> Self ### Parameters - **table** (CompatibilityTable) - Required - The compatibility table to use. ### Returns Self - A new Parser instance with the specified compatibility table. ### Example ```rust let parser = Parser::with_support(table); ``` ``` ```APIDOC ## Parser::with_support_and_capacity ### Description Creates a parser, setting the initial internal buffer capacity and directly supplying a CompatibilityTable. ### Method with_support_and_capacity ### Signature pub fn with_support_and_capacity(size: usize, table: CompatibilityTable) -> Self ### Parameters - **size** (usize) - Required - The initial internal buffer capacity. - **table** (CompatibilityTable) - Required - The compatibility table to use. ### Returns Self - A new Parser instance with the specified buffer capacity and compatibility table. ### Example ```rust let parser = Parser::with_support_and_capacity(256, table); ``` ``` ```APIDOC ## Parser::receive ### Description Receives bytes into the internal buffer and returns any events parsed from the internal buffer with the new bytes. ### Method receive ### Signature pub fn receive(&mut self, data: &[u8]) -> Vec ### Parameters - **data** (&[u8]) - Required - The bytes to be received. This should be sourced from the remote side of a connection. ### Returns Vec - Any events parsed from the internal buffer with the new bytes. ### Example ```rust let events = parser.receive(b"hi \xFF\xFF\r\n"); ``` ``` ```APIDOC ## Parser::linemode_enabled ### Description Gets whether the remote end supports and is using linemode. ### Method linemode_enabled ### Signature pub fn linemode_enabled(&self) -> bool ### Parameters None ### Returns bool - True if linemode is enabled, false otherwise. ### Example ```rust if parser.linemode_enabled() { // handle linemode } ``` ``` ```APIDOC ## Parser::escape_iac ### Description Escapes IAC bytes in data that is to be transmitted and treated as a non-IAC sequence. ### Method escape_iac ### Signature pub fn escape_iac(data: T) -> Bytes where Bytes: From ### Parameters - **data** (T) - Required - The data to escape. Must be convertible into Bytes. ### Returns Bytes - The escaped data with IAC bytes doubled. ### Example ```rust let out = Parser::escape_iac(vec![IAC, 1, 6, 2]); assert_eq!(&out[..], [IAC, IAC, 1, 6, 2]); ``` ``` -------------------------------- ### Parser::_will Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/compatibility/index.html Initiates a WILL negotiation for the given option, returning the bytes to send if needed. ```APIDOC ## Parser::_will ### Description Initiates a WILL negotiation for the given option, returning the bytes to send if needed. ### Method Method ### Endpoint `Parser::_will(option)` ### Parameters #### Path Parameters - **option** (u8) - Required - The Telnet option code (e.g., GMCP). ### Returns - **Option** - Some data to send to the socket if the negotiation should be initiated, otherwise None. ### Example ```rust if let Some(send) = parser._will(GMCP) { let _bytes_to_socket = send.to_bytes(); } ``` ``` -------------------------------- ### NAOLFD Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/telnet/op_option/constant.NAOLFD.html Documentation for the NAOLFD constant in the libmudtelnet-rs crate. ```APIDOC ## Constant NAOLFD ### Description Represents the NAOLFD option code (16) used in Telnet option negotiation. ### Value `pub const NAOLFD: u8 = 16;` ``` -------------------------------- ### vbytes! macro definition Source: https://docs.rs/libmudtelnet-rs/latest/libmudtelnet_rs/macro.vbytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Macro for calling Bytes::copy_from_slice(). Deprecated since 0.2.1; use Bytes::copy_from_slice directly instead. ```rust macro_rules! vbytes { ($slice:expr) => { ... }; } ```