pub struct DiscordIPC { /* private fields */ }Expand description
Primary struct for you to set and update Discord Rich Presences with.
Implementations§
Source§impl DiscordIPC
impl DiscordIPC
Sourcepub async fn new(client_id: &str) -> Result<Self>
pub async fn new(client_id: &str) -> Result<Self>
Examples found in repository?
More examples
examples/timed.rs (line 8)
7async fn main() {
8 let mut client = DiscordIPC::new("1463450870480900160").await.unwrap();
9
10 client.run().await.unwrap();
11
12 client
13 .set_activity("this runs", "for ten seconds")
14 .await
15 .unwrap();
16 sleep(Duration::from_secs(5)).await;
17 client.set_activity("believe it", "or not").await.unwrap();
18 sleep(Duration::from_secs(5)).await;
19
20 println!(
21 "Duration: {} seconds",
22 client.duration_since().unwrap().as_secs()
23 )
24}Sourcepub fn client_id(&self) -> String
pub fn client_id(&self) -> String
The Discord client ID that has been used to initialize this IPC client instance.
Sourcepub fn duration_since(&self) -> Result<Duration>
pub fn duration_since(&self) -> Result<Duration>
Duration since the IPC client was fired up.
Examples found in repository?
examples/timed.rs (line 22)
7async fn main() {
8 let mut client = DiscordIPC::new("1463450870480900160").await.unwrap();
9
10 client.run().await.unwrap();
11
12 client
13 .set_activity("this runs", "for ten seconds")
14 .await
15 .unwrap();
16 sleep(Duration::from_secs(5)).await;
17 client.set_activity("believe it", "or not").await.unwrap();
18 sleep(Duration::from_secs(5)).await;
19
20 println!(
21 "Duration: {} seconds",
22 client.duration_since().unwrap().as_secs()
23 )
24}Sourcepub async fn run(&mut self) -> Result<JoinHandle<Result<()>>>
pub async fn run(&mut self) -> Result<JoinHandle<Result<()>>>
Run the client. NOTE: Must be called before any .set_activity() calls.
Examples found in repository?
More examples
examples/timed.rs (line 10)
7async fn main() {
8 let mut client = DiscordIPC::new("1463450870480900160").await.unwrap();
9
10 client.run().await.unwrap();
11
12 client
13 .set_activity("this runs", "for ten seconds")
14 .await
15 .unwrap();
16 sleep(Duration::from_secs(5)).await;
17 client.set_activity("believe it", "or not").await.unwrap();
18 sleep(Duration::from_secs(5)).await;
19
20 println!(
21 "Duration: {} seconds",
22 client.duration_since().unwrap().as_secs()
23 )
24}Sourcepub async fn set_activity(&self, details: &str, state: &str) -> Result<()>
pub async fn set_activity(&self, details: &str, state: &str) -> Result<()>
Sets/updates the Discord Rich presence activity. NOTE: .run() must be executed prior to calling this.
Examples found in repository?
More examples
examples/timed.rs (line 13)
7async fn main() {
8 let mut client = DiscordIPC::new("1463450870480900160").await.unwrap();
9
10 client.run().await.unwrap();
11
12 client
13 .set_activity("this runs", "for ten seconds")
14 .await
15 .unwrap();
16 sleep(Duration::from_secs(5)).await;
17 client.set_activity("believe it", "or not").await.unwrap();
18 sleep(Duration::from_secs(5)).await;
19
20 println!(
21 "Duration: {} seconds",
22 client.duration_since().unwrap().as_secs()
23 )
24}Trait Implementations§
Source§impl Clone for DiscordIPC
impl Clone for DiscordIPC
Source§fn clone(&self) -> DiscordIPC
fn clone(&self) -> DiscordIPC
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for DiscordIPC
impl RefUnwindSafe for DiscordIPC
impl Send for DiscordIPC
impl Sync for DiscordIPC
impl Unpin for DiscordIPC
impl UnsafeUnpin for DiscordIPC
impl UnwindSafe for DiscordIPC
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