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
impl DiscordIPCSync
Sourcepub fn new(client_id: &str) -> Result<Self>
pub fn new(client_id: &str) -> Result<Self>
Creates a new synchronous Discord IPC client with the given client ID.
Examples found in repository?
More 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}Sourcepub fn client_id(&self) -> String
pub fn client_id(&self) -> String
Returns the Discord client ID that has been used to initialize this IPC client.
Sourcepub fn run(&mut self) -> Result<()>
pub fn run(&mut self) -> Result<()>
Run the IPC client. Must be called before any set_activity() calls.
Examples found in repository?
More 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}Sourcepub fn set_activity(&self, details: &str, state: &str) -> Result<()>
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?
More 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}Sourcepub fn clear_activity(&self) -> Result<()>
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}Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DiscordIPCSync
impl RefUnwindSafe for DiscordIPCSync
impl Send for DiscordIPCSync
impl Sync for DiscordIPCSync
impl Unpin for DiscordIPCSync
impl UnsafeUnpin for DiscordIPCSync
impl UnwindSafe for DiscordIPCSync
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more