### Enable RakNet Logging Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/index This function allows you to control the logging output for the RakNet implementation. You can enable or disable debug, error, and info logs using bit flags. For example, enabling debug and error logs would be represented by the integer 3. ```rust /// A switch to print Raknet logs 8 bit flag (00000000) enable print debug log = 1[00000001] enable print error log = 2[00000010] enable print info log = 4[00000100] enable print debug && error = 3[00000011] fn enable_raknet_log(flags: u8) { // Implementation details would go here } ``` -------------------------------- ### Get Local Address of Raknet Connection Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/struct Retrieves the local socket address used by the Raknet connection. This function returns a Result containing a `SocketAddr`, or a RaknetError. It's useful for determining the local endpoint of the connection. ```rust let mut socket = RaknetSocket::connect("127.0.0.1:19132".parse().unwrap()).await.unwrap(); assert_eq!(socket.local_addr().unwrap().ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))); ``` -------------------------------- ### Get Peer Address of Raknet Connection Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/struct Retrieves the socket address of the remote peer for the current Raknet connection. This function returns a Result containing a `SocketAddr`, or a RaknetError if the address cannot be determined. It's useful for identifying the connected server. ```rust let socket = RaknetSocket::connect("127.0.0.1:19132".parse().unwrap()).await.unwrap(); assert_eq!(socket.peer_addr().unwrap(), SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 19132))); ``` -------------------------------- ### Connect to Raknet Server Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/struct Establishes a connection to a Raknet server at the specified address and returns a Raknet socket. This function is asynchronous and returns a Result, indicating success or a RaknetError. It's used for initiating communication with a Raknet server. ```rust let socket = RaknetSocket::connect("127.0.0.1:19132".parse().unwrap()).await.unwrap(); socket.send(&[0xfe], Reliability::ReliableOrdered).await.unwrap(); let buf = socket.recv().await.unwrap(); if buf[0] == 0xfe{ //do something } ``` -------------------------------- ### Add rust-raknet Dependency to Cargo.toml Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/index This code snippet demonstrates how to add the rust-raknet crate as a dependency to your Rust project's Cargo.toml file. This is the standard way to include external libraries in a Rust project. ```toml # Cargo.toml [dependencies] rust-raknet = "*" ``` -------------------------------- ### Set Raknet Packet Loss Rate for Testing Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/struct Allows setting a simulated packet loss rate for testing purposes. The `stage` parameter, ranging from 0 to 10, corresponds to a packet loss rate from 0% to 100%. This is a mutable operation on the RaknetSocket. ```rust let mut socket = RaknetSocket::connect("127.0.0.1:19132".parse().unwrap()).await.unwrap(); // set 20% loss packet rate. socket.set_loss_rate(8); ``` -------------------------------- ### Ping Raknet Server Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/struct Sends an unconnected ping to a Raknet server to determine its latency and retrieve its Message of the Day (MOTD). This function is asynchronous and returns a Result containing a tuple of latency (i64) and MOTD (String), or a RaknetError. It's useful for checking server status and responsiveness. ```rust let (latency, motd) = socket::RaknetSocket::ping("127.0.0.1:19132".parse().unwrap()).await.unwrap(); assert!((0..10).contains(&latency)); ``` -------------------------------- ### Clone Reliability Enum Variant in Rust Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/enum This Rust code implements the `clone` method for the Reliability enum. It allows creating a new instance of a Reliability variant that is a copy of an existing one. This is a standard implementation for enums that represent distinct states and is crucial for managing state copies in concurrent or stateful applications. ```rust fn clone(&self) -> Reliability ``` -------------------------------- ### Rust Multi-Lane Data Zipping with VZip Trait Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/enum The `VZip` trait is implemented for type `T` when `V` is a `MultiLane`. It provides a `vzip` method to combine lanes of data. ```rust /// Zips lanes of data together. fn vzip(self) -> V; ``` -------------------------------- ### Reliability Enum Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/enum Defines the reliability levels for Raknet transport packets, including Unreliable, UnreliableSequenced, Reliable, ReliableOrdered, and ReliableSequenced. ```APIDOC ## Enum Reliability ### Description Enumeration type options for Raknet transport reliability. ### Variants * **Unreliable = 0** Unreliable packets are sent by straight UDP. They may arrive out of order, or not at all. This is best for data that is unimportant, or data that you send very frequently so even if some packets are missed newer packets will compensate. * **UnreliableSequenced = 1** Unreliable sequenced packets are the same as unreliable packets, except that only the newest packet is ever accepted. Older packets are ignored. * **Reliable = 2** Reliable packets are UDP packets monitored by a reliability layer to ensure they arrive at the destination. No packet ordering. * **ReliableOrdered = 3** Reliable ordered packets are UDP packets monitored by a reliability layer to ensure they arrive at the destination and are ordered at the destination. * **ReliableSequenced = 4** Reliable sequenced packets are UDP packets monitored by a reliability layer to ensure they arrive at the destination and are sequenced at the destination. ### Implementations #### impl Reliability * `pub fn to_u8(&self) -> u8` * `pub fn from(flags: u8) -> Result` ``` -------------------------------- ### Send Packet via Raknet Socket Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/struct Sends a packet of data over an established Raknet connection. The first byte of the packet must be `0xfe`. For reliability levels other than ReliableOrdered, the packet size must be less than MTU - 60. This function is asynchronous and returns a Result indicating success or a RaknetError, such as PacketSizeExceedMTU. ```rust let socket = RaknetSocket::connect("127.0.0.1:19132".parse().unwrap()).await.unwrap(); socket.send(&[0xfe], Reliability::ReliableOrdered).await.unwrap(); ``` -------------------------------- ### Create Reliability Enum from u8 in Rust Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/enum This Rust function attempts to create a Reliability enum variant from a u8 value. It returns a `Result` containing either the corresponding Reliability enum variant or a `RaknetError` if the provided u8 value does not map to any known reliability level. This is essential for deserializing network data into the correct enum state. ```rust pub fn from(flags: u8) -> Result ``` -------------------------------- ### Rust Fallible Type Conversion with TryInto Trait Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/enum The `TryInto` trait provides a fallible conversion from type `T` to type `U`. It leverages the `TryFrom` implementation for the target type. The error type is determined by the `TryFrom` implementation. ```rust /// The type returned in the event of a conversion error. type Error = >::Error; /// Performs the conversion. fn try_into(self) -> Result>::Error>; ``` -------------------------------- ### Receive Packet from Raknet Socket Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/struct Receives a packet of data from an established Raknet connection. This is an asynchronous function that returns a Result containing a `Vec` representing the received data, or a RaknetError. It's used to read incoming messages from the server. ```rust let socket = RaknetSocket::connect("127.0.0.1:19132".parse().unwrap()).await.unwrap(); let buf = socket.recv().await.unwrap(); if buf[0] == 0xfe{ //do something } ``` -------------------------------- ### Rust Fallible Type Conversion with TryFrom Trait Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/enum The `TryFrom` trait enables fallible conversions from type `U` to type `T`. If the conversion fails, an `Infallible` error type is returned, indicating that the conversion is always successful under normal circumstances. ```rust /// The type returned in the event of a conversion error. type Error = Infallible; /// Performs the conversion. fn try_from(value: U) -> Result>::Error>; ``` -------------------------------- ### Flush Raknet Socket Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/struct Waits for all outstanding packets to be acknowledged by the remote peer. This is an asynchronous function that returns a Result, indicating success or a RaknetError. It ensures that all sent data has been reliably received before proceeding. ```rust let socket = RaknetSocket::connect("127.0.0.1:19132".parse().unwrap()).await.unwrap(); socket.send(&[0xfe], Reliability::ReliableOrdered).await.unwrap(); socket.flush().await.unwrap(); ``` -------------------------------- ### Rust Creating Owned Data with ToOwned Trait Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/enum The `ToOwned` trait provides methods for creating owned data from borrowed data. It's typically used for cloning or replacing owned data with borrowed data. ```rust /// The resulting type after obtaining ownership. type Owned = T; /// Creates owned data from borrowed data, usually by cloning. /// Read more fn to_owned(&self) -> T; /// Uses borrowed data to replace owned data, usually by cloning. /// Read more fn clone_into(&self, target: &mut T); ``` -------------------------------- ### Convert Reliability Enum to u8 in Rust Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/enum This Rust function converts a Reliability enum variant to its corresponding u8 representation. This is useful for network serialization or when interacting with systems that expect a byte-based representation of reliability levels. It takes a `&self` reference to the enum variant and returns a `u8`. ```rust pub fn to_u8(&self) -> u8 ``` -------------------------------- ### Define Raknet Reliability Enum in Rust Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/enum This Rust code defines an enumeration for Raknet transport reliability. It includes variants like Unreliable, UnreliableSequenced, Reliable, ReliableOrdered, and ReliableSequenced, each corresponding to a numerical value representing its transmission strategy. This enum is fundamental for configuring network communication reliability. ```rust pub enum Reliability { Unreliable = 0, UnreliableSequenced = 1, Reliable = 2, ReliableOrdered = 3, ReliableSequenced = 4, } ``` -------------------------------- ### Rust Type Conversion with Into Trait Source: https://docs.rs/rust-raknet/0.12.0/rust_raknet/enum The `Into` trait allows for conversion from type `T` to type `U` by calling `U::from(self)`. The specific conversion logic is determined by the implementation of `From for U`. ```rust /// Calls `U::from(self)`. /// That is, this conversion is whatever the implementation of `From for U` chooses to do. fn into(self) -> U ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.