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
Provided methods
fn connect(&mut self) -> Result<(), Box<dyn Error>>
[src]
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]
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(
&mut self,
data: impl Serialize,
opcode: u8
) -> Result<(), Box<dyn Error>>
[src]
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]
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()?);