Skip to main content

DiscordIPCSync

Struct DiscordIPCSync 

Source
pub struct DiscordIPCSync { /* private fields */ }
Expand description

Synchronous wrapper around DiscordIPC for use in non-async contexts. All operations block on an internal Tokio runtime.

Implementations§

Source§

impl DiscordIPCSync

Source

pub fn new(client_id: &str) -> Result<Self>

Creates a new synchronous Discord IPC client with the given client ID.

Examples found in repository?
examples/indefinite-sync.rs (line 4)
3fn main() {
4    let mut client = DiscordIPCSync::new("1463450870480900160").unwrap();
5
6    client.run().unwrap();
7    client.set_activity("this runs", "forever").unwrap();
8    client.wait().unwrap();
9}
More examples
Hide additional examples
examples/timed-sync.rs (line 6)
5fn main() {
6    let mut client = DiscordIPCSync::new("1463450870480900160").unwrap();
7
8    // first run
9    client.run().unwrap();
10
11    client.set_activity("this runs", "for ten seconds").unwrap();
12    sleep(Duration::from_secs(5));
13    client.set_activity("believe it", "or not").unwrap();
14    sleep(Duration::from_secs(5));
15
16    client.clear_activity().unwrap();
17
18    // if you want to drop the connection here:
19    // client.close().unwrap();
20
21    // optional sleep
22    sleep(Duration::from_secs(2));
23
24    // if you closed the connection, you must run it afterwards:
25    // client.run().unwrap();
26
27    // 2nd run
28    client.set_activity("this is the", "second run").unwrap();
29    sleep(Duration::from_secs(5));
30    client
31        .set_activity("which also runs", "for ten seconds")
32        .unwrap();
33    sleep(Duration::from_secs(5));
34}
Source

pub fn client_id(&self) -> String

Returns the Discord client ID that has been used to initialize this IPC client.

Source

pub fn run(&mut self) -> Result<()>

Run the IPC client. Must be called before any set_activity() calls.

Examples found in repository?
examples/indefinite-sync.rs (line 6)
3fn main() {
4    let mut client = DiscordIPCSync::new("1463450870480900160").unwrap();
5
6    client.run().unwrap();
7    client.set_activity("this runs", "forever").unwrap();
8    client.wait().unwrap();
9}
More examples
Hide additional examples
examples/timed-sync.rs (line 9)
5fn main() {
6    let mut client = DiscordIPCSync::new("1463450870480900160").unwrap();
7
8    // first run
9    client.run().unwrap();
10
11    client.set_activity("this runs", "for ten seconds").unwrap();
12    sleep(Duration::from_secs(5));
13    client.set_activity("believe it", "or not").unwrap();
14    sleep(Duration::from_secs(5));
15
16    client.clear_activity().unwrap();
17
18    // if you want to drop the connection here:
19    // client.close().unwrap();
20
21    // optional sleep
22    sleep(Duration::from_secs(2));
23
24    // if you closed the connection, you must run it afterwards:
25    // client.run().unwrap();
26
27    // 2nd run
28    client.set_activity("this is the", "second run").unwrap();
29    sleep(Duration::from_secs(5));
30    client
31        .set_activity("which also runs", "for ten seconds")
32        .unwrap();
33    sleep(Duration::from_secs(5));
34}
Source

pub fn wait(&mut self) -> Result<()>

Waits for the primary IPC task to finish.

Examples found in repository?
examples/indefinite-sync.rs (line 8)
3fn main() {
4    let mut client = DiscordIPCSync::new("1463450870480900160").unwrap();
5
6    client.run().unwrap();
7    client.set_activity("this runs", "forever").unwrap();
8    client.wait().unwrap();
9}
Source

pub fn set_activity(&self, details: &str, state: &str) -> Result<()>

Sets/updates the Discord Rich Presence activity. run() must be called prior to calling this.

Examples found in repository?
examples/indefinite-sync.rs (line 7)
3fn main() {
4    let mut client = DiscordIPCSync::new("1463450870480900160").unwrap();
5
6    client.run().unwrap();
7    client.set_activity("this runs", "forever").unwrap();
8    client.wait().unwrap();
9}
More examples
Hide additional examples
examples/timed-sync.rs (line 11)
5fn main() {
6    let mut client = DiscordIPCSync::new("1463450870480900160").unwrap();
7
8    // first run
9    client.run().unwrap();
10
11    client.set_activity("this runs", "for ten seconds").unwrap();
12    sleep(Duration::from_secs(5));
13    client.set_activity("believe it", "or not").unwrap();
14    sleep(Duration::from_secs(5));
15
16    client.clear_activity().unwrap();
17
18    // if you want to drop the connection here:
19    // client.close().unwrap();
20
21    // optional sleep
22    sleep(Duration::from_secs(2));
23
24    // if you closed the connection, you must run it afterwards:
25    // client.run().unwrap();
26
27    // 2nd run
28    client.set_activity("this is the", "second run").unwrap();
29    sleep(Duration::from_secs(5));
30    client
31        .set_activity("which also runs", "for ten seconds")
32        .unwrap();
33    sleep(Duration::from_secs(5));
34}
Source

pub fn clear_activity(&self) -> Result<()>

Clears the current Discord Rich Presence activity without closing the session.

Examples found in repository?
examples/timed-sync.rs (line 16)
5fn main() {
6    let mut client = DiscordIPCSync::new("1463450870480900160").unwrap();
7
8    // first run
9    client.run().unwrap();
10
11    client.set_activity("this runs", "for ten seconds").unwrap();
12    sleep(Duration::from_secs(5));
13    client.set_activity("believe it", "or not").unwrap();
14    sleep(Duration::from_secs(5));
15
16    client.clear_activity().unwrap();
17
18    // if you want to drop the connection here:
19    // client.close().unwrap();
20
21    // optional sleep
22    sleep(Duration::from_secs(2));
23
24    // if you closed the connection, you must run it afterwards:
25    // client.run().unwrap();
26
27    // 2nd run
28    client.set_activity("this is the", "second run").unwrap();
29    sleep(Duration::from_secs(5));
30    client
31        .set_activity("which also runs", "for ten seconds")
32        .unwrap();
33    sleep(Duration::from_secs(5));
34}
Source

pub fn close(&mut self) -> Result<()>

Closes the current session of Rich Presence activity. After this, you can safely call run() again.

Trait Implementations§

Source§

impl Debug for DiscordIPCSync

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.