Crate enet

source · []
Expand description

This crate provides high-level bindings for the ENet networking library.

ENet provides features that are most typically used by games, such as unreliable but sequenced data transfer over UDP. ENet also provides optional reliability, and provides multiple channels over a single connection. For more info see the ENet website.

This crate aims to provide high-level, rust-y binding for the ENet library, based on existing low-level C-bindings, so users don’t have to deal with ffi.

The official ENet documentation and tutorials are a good starting point to working with ENet. Most principles and names should be straight-forward to transfer to this library.

Examples

This will initialize ENet and deinitialize it when the Enet-instance - and all references to it - are dropped:

use enet::Enet;

// `Enet::new()` initializes ENet when it is first called.
let enet = Enet::new().unwrap();

// Deinitialization is handled automatically (using Arc).

Also check out the examples in the code, as well as the examples from the official ENet website and from the enet-sys crate. There are also an example server and client in the examples directory on github.

Thread-safety

ENet claims to be “mostly” thread-safe as long as access to individual Host-instances is handled in a synchronized manner. This is kind of an unclear statement, but this API tries to follow that as good as possible. So if the rust compilers allows you to send/sync an object between threads, it should be safe to do so.

If you used no unsafe code and the library blows up in your face, that is considered a bug. Please report any bug you encounter via github.

Structs

An IPv4 address that can be used with the ENet API.

Main API entry point. Provides methods such as host and peer creation.

Generic ENet error, returned by many API functions.

A Host represents one endpoint of an ENet connection. Created through Enet.

A packet that can be sent or retrieved on an ENet-connection.

This struct represents an endpoint in an ENet-connection.

A packet received directly from a Peer.

Enums

Represents a bandwidth limit or unlimited.

Represents a channel limit or unlimited.

This enum represents an event that can occur when servicing an EnetHost.

An error that can occur when initializing ENet.

Mode that can be set when transmitting a packet.

Describes the state a Peer is in.

Functions

Returns the version of the linked ENet library.

Type Definitions