Trait discord_rich_presence::DiscordIpc[][src]

pub trait DiscordIpc {
    fn close(&mut self) -> Result<(), Box<dyn Error>>;

    fn connect(&mut self) -> Result<(), Box<dyn Error>> { ... }
fn reconnect(&mut self) -> Result<(), Box<dyn Error>> { ... }
fn send_handshake(&mut self) -> Result<(), Box<dyn Error>> { ... }
fn send(
        &mut self,
        data: impl Serialize,
        opcode: u8
    ) -> Result<(), Box<dyn Error>> { ... }
fn recv(&mut self) -> Result<(u32, Value), Box<dyn Error>> { ... }
fn set_activity(
        &mut self,
        activity_payload: impl Serialize
    ) -> Result<(), Box<dyn Error>> { ... } }
Expand description

A client that connects to and communicates with the Discord IPC.

Required methods

fn close(&mut self) -> Result<(), Box<dyn Error>>[src]

Closes the Discord IPC connection. Implementation is dependent on platform.

Provided methods

fn connect(&mut self) -> Result<(), Box<dyn Error>>[src]

Connects the client to the Discord IPC.

This method attempts to first establish a connection, and then sends a handshake.

Errors

Returns an Err variant if the client failed to connect to the socket, or if it failed to send a handshake.

Examples

let mut client = discord_rich_presence::new_client("<some client id>")?;
client.connect()?;

fn reconnect(&mut self) -> Result<(), Box<dyn Error>>[src]

Reconnects to the Discord IPC.

This method closes the client’s active connection, then re-connects it and re-sends a handshake.

Errors

Returns an Err variant if the client failed to connect to the socket, or if it failed to send a handshake.

Examples

let mut client = discord_rich_presence::new_client("<some client id>")?;
client.connect()?;
 
client.close()?;
client.reconnect()?;

fn send_handshake(&mut self) -> Result<(), Box<dyn Error>>[src]

Handshakes the Discord IPC.

This method sends the handshake signal to the IPC. It is usually not called manually, as it is automatically called by connect and/or reconnect.

Errors

Returns an Err variant if sending the handshake failed.

fn send(
    &mut self,
    data: impl Serialize,
    opcode: u8
) -> Result<(), Box<dyn Error>>
[src]

Sends JSON data to the Discord IPC.

This method takes data (must implement serde::Serialize) and an opcode as its parameters.

Errors

Returns an Err variant if:

  • The data could not be serialized as JSON
  • Writing to the socket failed

Examples

let payload = serde_json::json!({ "field": "value" });
client.send(payload, 0)?;

fn recv(&mut self) -> Result<(u32, Value), Box<dyn Error>>[src]

Receives an opcode and JSON data from the Discord IPC.

This method returns any data received from the IPC. It returns a tuple containing the opcode, and the JSON data.

Errors

Returns an Err variant if reading the socket was unsuccessful.

Examples

client.connect_ipc()?;
client.send_handshake()?;
 
println!("{:?}", client.recv()?);

fn set_activity(
    &mut self,
    activity_payload: impl Serialize
) -> Result<(), Box<dyn Error>>
[src]

Sets a Discord activity.

This method is an abstraction of send, wrapping it such that only an activity payload is required.

Errors

Returns an Err variant if sending the payload failed.

Implementors