Skip to main content

ActivityBuilder

Struct ActivityBuilder 

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

A builder for a Rich Presence activity. To build a ActivitySpec out of it, use ActivityBuilder::build.

Implementations§

Source§

impl ActivityBuilder

Source

pub fn name(self, name: impl Into<String>) -> Self

Name of the activity.

Examples found in repository?
examples/simple.rs (line 8)
4async fn main() -> Result<(), PresenceError> {
5    let mut runner = PresenceRunner::new("1463450870480900160");
6
7    let activity = Activity::new()
8        .name("cool app name")
9        .details("Something?")
10        .state("Probably~")
11        .build()?;
12
13    let client = runner.run(true).await?;
14    client.set_activity(activity).await?;
15
16    // indefinitely block here
17    runner.wait().await?;
18
19    Ok(())
20}
Source

pub fn details(self, text: impl Into<String>) -> Self

Top text for your activity.

Examples found in repository?
examples/simple.rs (line 9)
4async fn main() -> Result<(), PresenceError> {
5    let mut runner = PresenceRunner::new("1463450870480900160");
6
7    let activity = Activity::new()
8        .name("cool app name")
9        .details("Something?")
10        .state("Probably~")
11        .build()?;
12
13    let client = runner.run(true).await?;
14    client.set_activity(activity).await?;
15
16    // indefinitely block here
17    runner.wait().await?;
18
19    Ok(())
20}
More examples
Hide additional examples
examples/timed.rs (line 32)
13async fn main() -> Result<(), PresenceError> {
14    // simple atomic counter
15    let count = Arc::new(AtomicUsize::new(0));
16
17    let mut runner = PresenceRunner::new("1463450870480900160")
18        .on_ready(|data| println!("Connected to user: {}", data.user.username()))
19        .on_activity_send(move |_| {
20
21            // increments the counter with every send_activity()
22            let val = count.fetch_add(1, Ordering::Relaxed) + 1;
23
24            println!("Activity {val} sent successfully.")
25
26        })
27        .show_errors() // enables verbose error logging
28    ;
29
30    // create activities for later use
31    let activity_1 = Activity::new()
32        .details("this runs")
33        .state("for ten seconds")
34        .build()?;
35
36    let activity_2 = Activity::new()
37        .details("believe it")
38        .state("or not")
39        .build()?;
40
41    let closing_activity = Activity::new()
42        .details("closing presence in...")
43        .duration(Duration::from_secs(5))
44        .small_image("status")
45        .build()?;
46
47    // first run
48    let client = runner.run(true).await?;
49
50    client.set_activity(activity_1).await?;
51    sleep(Duration::from_secs(5)).await;
52    client.set_activity(activity_2).await?;
53    sleep(Duration::from_secs(5)).await;
54    client.set_activity(closing_activity).await?;
55    sleep(Duration::from_secs(5)).await;
56
57    client.close().await?;
58
59    println!("Stopped.");
60
61    Ok(())
62}
examples/indefinite.rs (line 37)
8async fn main() -> Result<(), PresenceError> {
9    let mut runner = PresenceRunner::new("1463450870480900160")
10        .on_ready(|data| {
11            println!(
12                "RPC version: v{}; Connected to user: {}",
13                data.version(),
14                data.user.global_name().unwrap_or_default(),
15            )
16        })
17        .on_activity_send(|data| {
18            println!(
19                "Activity sent to app! (running on {})\nCreated at: {}",
20                data.platform().unwrap_or_default(),
21                data.activity.created_at()
22            );
23        })
24        .on_disconnect(|f| println!("Disconnected: {f:?}"))
25        .show_errors() // enables verbose error logging
26        .on_retry(move |c| {
27            if c % 10 == 0 {
28                println!("Retry count {c}; is Discord open?");
29            }
30        });
31
32    let client = runner.run(true).await?;
33
34    // the activity can include any combination of builder function calls
35    let activity = Activity::new()
36        .activity_type(ActivityType::Playing)
37        .details("epic game")
38        .details_url("https://github.com/hitblast")
39        .status_display_type(StatusDisplayType::Details)
40        .large_image("game_icon")
41        .large_text("Playing a game")
42        .large_url("https://hitblast.github.io/")
43        .small_image("status")
44        .small_text("Online")
45        .build()?;
46
47    client.set_activity(activity).await?;
48
49    // indefinitely block here
50    runner.wait().await?;
51
52    Ok(())
53}
Source

pub fn details_url(self, url: impl Into<String>) -> Self

URL for the top text of your activity.

Examples found in repository?
examples/indefinite.rs (line 38)
8async fn main() -> Result<(), PresenceError> {
9    let mut runner = PresenceRunner::new("1463450870480900160")
10        .on_ready(|data| {
11            println!(
12                "RPC version: v{}; Connected to user: {}",
13                data.version(),
14                data.user.global_name().unwrap_or_default(),
15            )
16        })
17        .on_activity_send(|data| {
18            println!(
19                "Activity sent to app! (running on {})\nCreated at: {}",
20                data.platform().unwrap_or_default(),
21                data.activity.created_at()
22            );
23        })
24        .on_disconnect(|f| println!("Disconnected: {f:?}"))
25        .show_errors() // enables verbose error logging
26        .on_retry(move |c| {
27            if c % 10 == 0 {
28                println!("Retry count {c}; is Discord open?");
29            }
30        });
31
32    let client = runner.run(true).await?;
33
34    // the activity can include any combination of builder function calls
35    let activity = Activity::new()
36        .activity_type(ActivityType::Playing)
37        .details("epic game")
38        .details_url("https://github.com/hitblast")
39        .status_display_type(StatusDisplayType::Details)
40        .large_image("game_icon")
41        .large_text("Playing a game")
42        .large_url("https://hitblast.github.io/")
43        .small_image("status")
44        .small_text("Online")
45        .build()?;
46
47    client.set_activity(activity).await?;
48
49    // indefinitely block here
50    runner.wait().await?;
51
52    Ok(())
53}
Source

pub fn state(self, text: impl Into<String>) -> Self

Bottom text (top if field details is missing) for your activity.

Examples found in repository?
examples/simple.rs (line 10)
4async fn main() -> Result<(), PresenceError> {
5    let mut runner = PresenceRunner::new("1463450870480900160");
6
7    let activity = Activity::new()
8        .name("cool app name")
9        .details("Something?")
10        .state("Probably~")
11        .build()?;
12
13    let client = runner.run(true).await?;
14    client.set_activity(activity).await?;
15
16    // indefinitely block here
17    runner.wait().await?;
18
19    Ok(())
20}
More examples
Hide additional examples
examples/timed.rs (line 33)
13async fn main() -> Result<(), PresenceError> {
14    // simple atomic counter
15    let count = Arc::new(AtomicUsize::new(0));
16
17    let mut runner = PresenceRunner::new("1463450870480900160")
18        .on_ready(|data| println!("Connected to user: {}", data.user.username()))
19        .on_activity_send(move |_| {
20
21            // increments the counter with every send_activity()
22            let val = count.fetch_add(1, Ordering::Relaxed) + 1;
23
24            println!("Activity {val} sent successfully.")
25
26        })
27        .show_errors() // enables verbose error logging
28    ;
29
30    // create activities for later use
31    let activity_1 = Activity::new()
32        .details("this runs")
33        .state("for ten seconds")
34        .build()?;
35
36    let activity_2 = Activity::new()
37        .details("believe it")
38        .state("or not")
39        .build()?;
40
41    let closing_activity = Activity::new()
42        .details("closing presence in...")
43        .duration(Duration::from_secs(5))
44        .small_image("status")
45        .build()?;
46
47    // first run
48    let client = runner.run(true).await?;
49
50    client.set_activity(activity_1).await?;
51    sleep(Duration::from_secs(5)).await;
52    client.set_activity(activity_2).await?;
53    sleep(Duration::from_secs(5)).await;
54    client.set_activity(closing_activity).await?;
55    sleep(Duration::from_secs(5)).await;
56
57    client.close().await?;
58
59    println!("Stopped.");
60
61    Ok(())
62}
Source

pub fn state_url(self, url: impl Into<String>) -> Self

URL for the state of your activity.

Source

pub fn large_image(self, key: impl Into<String>) -> Self

Large image for your activity (e.g. game icon)

Examples found in repository?
examples/indefinite.rs (line 40)
8async fn main() -> Result<(), PresenceError> {
9    let mut runner = PresenceRunner::new("1463450870480900160")
10        .on_ready(|data| {
11            println!(
12                "RPC version: v{}; Connected to user: {}",
13                data.version(),
14                data.user.global_name().unwrap_or_default(),
15            )
16        })
17        .on_activity_send(|data| {
18            println!(
19                "Activity sent to app! (running on {})\nCreated at: {}",
20                data.platform().unwrap_or_default(),
21                data.activity.created_at()
22            );
23        })
24        .on_disconnect(|f| println!("Disconnected: {f:?}"))
25        .show_errors() // enables verbose error logging
26        .on_retry(move |c| {
27            if c % 10 == 0 {
28                println!("Retry count {c}; is Discord open?");
29            }
30        });
31
32    let client = runner.run(true).await?;
33
34    // the activity can include any combination of builder function calls
35    let activity = Activity::new()
36        .activity_type(ActivityType::Playing)
37        .details("epic game")
38        .details_url("https://github.com/hitblast")
39        .status_display_type(StatusDisplayType::Details)
40        .large_image("game_icon")
41        .large_text("Playing a game")
42        .large_url("https://hitblast.github.io/")
43        .small_image("status")
44        .small_text("Online")
45        .build()?;
46
47    client.set_activity(activity).await?;
48
49    // indefinitely block here
50    runner.wait().await?;
51
52    Ok(())
53}
Source

pub fn large_text(self, text: impl Into<String>) -> Self

Text for the large image of your activity.

Examples found in repository?
examples/indefinite.rs (line 41)
8async fn main() -> Result<(), PresenceError> {
9    let mut runner = PresenceRunner::new("1463450870480900160")
10        .on_ready(|data| {
11            println!(
12                "RPC version: v{}; Connected to user: {}",
13                data.version(),
14                data.user.global_name().unwrap_or_default(),
15            )
16        })
17        .on_activity_send(|data| {
18            println!(
19                "Activity sent to app! (running on {})\nCreated at: {}",
20                data.platform().unwrap_or_default(),
21                data.activity.created_at()
22            );
23        })
24        .on_disconnect(|f| println!("Disconnected: {f:?}"))
25        .show_errors() // enables verbose error logging
26        .on_retry(move |c| {
27            if c % 10 == 0 {
28                println!("Retry count {c}; is Discord open?");
29            }
30        });
31
32    let client = runner.run(true).await?;
33
34    // the activity can include any combination of builder function calls
35    let activity = Activity::new()
36        .activity_type(ActivityType::Playing)
37        .details("epic game")
38        .details_url("https://github.com/hitblast")
39        .status_display_type(StatusDisplayType::Details)
40        .large_image("game_icon")
41        .large_text("Playing a game")
42        .large_url("https://hitblast.github.io/")
43        .small_image("status")
44        .small_text("Online")
45        .build()?;
46
47    client.set_activity(activity).await?;
48
49    // indefinitely block here
50    runner.wait().await?;
51
52    Ok(())
53}
Source

pub fn large_url(self, url: impl Into<String>) -> Self

URL for the large image of your activity.

Examples found in repository?
examples/indefinite.rs (line 42)
8async fn main() -> Result<(), PresenceError> {
9    let mut runner = PresenceRunner::new("1463450870480900160")
10        .on_ready(|data| {
11            println!(
12                "RPC version: v{}; Connected to user: {}",
13                data.version(),
14                data.user.global_name().unwrap_or_default(),
15            )
16        })
17        .on_activity_send(|data| {
18            println!(
19                "Activity sent to app! (running on {})\nCreated at: {}",
20                data.platform().unwrap_or_default(),
21                data.activity.created_at()
22            );
23        })
24        .on_disconnect(|f| println!("Disconnected: {f:?}"))
25        .show_errors() // enables verbose error logging
26        .on_retry(move |c| {
27            if c % 10 == 0 {
28                println!("Retry count {c}; is Discord open?");
29            }
30        });
31
32    let client = runner.run(true).await?;
33
34    // the activity can include any combination of builder function calls
35    let activity = Activity::new()
36        .activity_type(ActivityType::Playing)
37        .details("epic game")
38        .details_url("https://github.com/hitblast")
39        .status_display_type(StatusDisplayType::Details)
40        .large_image("game_icon")
41        .large_text("Playing a game")
42        .large_url("https://hitblast.github.io/")
43        .small_image("status")
44        .small_text("Online")
45        .build()?;
46
47    client.set_activity(activity).await?;
48
49    // indefinitely block here
50    runner.wait().await?;
51
52    Ok(())
53}
Source

pub fn small_image(self, key: impl Into<String>) -> Self

Small image for your activity (e.g. game icon)

Examples found in repository?
examples/timed.rs (line 44)
13async fn main() -> Result<(), PresenceError> {
14    // simple atomic counter
15    let count = Arc::new(AtomicUsize::new(0));
16
17    let mut runner = PresenceRunner::new("1463450870480900160")
18        .on_ready(|data| println!("Connected to user: {}", data.user.username()))
19        .on_activity_send(move |_| {
20
21            // increments the counter with every send_activity()
22            let val = count.fetch_add(1, Ordering::Relaxed) + 1;
23
24            println!("Activity {val} sent successfully.")
25
26        })
27        .show_errors() // enables verbose error logging
28    ;
29
30    // create activities for later use
31    let activity_1 = Activity::new()
32        .details("this runs")
33        .state("for ten seconds")
34        .build()?;
35
36    let activity_2 = Activity::new()
37        .details("believe it")
38        .state("or not")
39        .build()?;
40
41    let closing_activity = Activity::new()
42        .details("closing presence in...")
43        .duration(Duration::from_secs(5))
44        .small_image("status")
45        .build()?;
46
47    // first run
48    let client = runner.run(true).await?;
49
50    client.set_activity(activity_1).await?;
51    sleep(Duration::from_secs(5)).await;
52    client.set_activity(activity_2).await?;
53    sleep(Duration::from_secs(5)).await;
54    client.set_activity(closing_activity).await?;
55    sleep(Duration::from_secs(5)).await;
56
57    client.close().await?;
58
59    println!("Stopped.");
60
61    Ok(())
62}
More examples
Hide additional examples
examples/indefinite.rs (line 43)
8async fn main() -> Result<(), PresenceError> {
9    let mut runner = PresenceRunner::new("1463450870480900160")
10        .on_ready(|data| {
11            println!(
12                "RPC version: v{}; Connected to user: {}",
13                data.version(),
14                data.user.global_name().unwrap_or_default(),
15            )
16        })
17        .on_activity_send(|data| {
18            println!(
19                "Activity sent to app! (running on {})\nCreated at: {}",
20                data.platform().unwrap_or_default(),
21                data.activity.created_at()
22            );
23        })
24        .on_disconnect(|f| println!("Disconnected: {f:?}"))
25        .show_errors() // enables verbose error logging
26        .on_retry(move |c| {
27            if c % 10 == 0 {
28                println!("Retry count {c}; is Discord open?");
29            }
30        });
31
32    let client = runner.run(true).await?;
33
34    // the activity can include any combination of builder function calls
35    let activity = Activity::new()
36        .activity_type(ActivityType::Playing)
37        .details("epic game")
38        .details_url("https://github.com/hitblast")
39        .status_display_type(StatusDisplayType::Details)
40        .large_image("game_icon")
41        .large_text("Playing a game")
42        .large_url("https://hitblast.github.io/")
43        .small_image("status")
44        .small_text("Online")
45        .build()?;
46
47    client.set_activity(activity).await?;
48
49    // indefinitely block here
50    runner.wait().await?;
51
52    Ok(())
53}
Source

pub fn small_text(self, text: impl Into<String>) -> Self

Text for the small image of your activity.

Examples found in repository?
examples/indefinite.rs (line 44)
8async fn main() -> Result<(), PresenceError> {
9    let mut runner = PresenceRunner::new("1463450870480900160")
10        .on_ready(|data| {
11            println!(
12                "RPC version: v{}; Connected to user: {}",
13                data.version(),
14                data.user.global_name().unwrap_or_default(),
15            )
16        })
17        .on_activity_send(|data| {
18            println!(
19                "Activity sent to app! (running on {})\nCreated at: {}",
20                data.platform().unwrap_or_default(),
21                data.activity.created_at()
22            );
23        })
24        .on_disconnect(|f| println!("Disconnected: {f:?}"))
25        .show_errors() // enables verbose error logging
26        .on_retry(move |c| {
27            if c % 10 == 0 {
28                println!("Retry count {c}; is Discord open?");
29            }
30        });
31
32    let client = runner.run(true).await?;
33
34    // the activity can include any combination of builder function calls
35    let activity = Activity::new()
36        .activity_type(ActivityType::Playing)
37        .details("epic game")
38        .details_url("https://github.com/hitblast")
39        .status_display_type(StatusDisplayType::Details)
40        .large_image("game_icon")
41        .large_text("Playing a game")
42        .large_url("https://hitblast.github.io/")
43        .small_image("status")
44        .small_text("Online")
45        .build()?;
46
47    client.set_activity(activity).await?;
48
49    // indefinitely block here
50    runner.wait().await?;
51
52    Ok(())
53}
Source

pub fn small_url(self, url: impl Into<String>) -> Self

URL for the small image of your activity.

Source

pub fn activity_type(self, type: ActivityType) -> Self

The type of activity you want to create.

Examples found in repository?
examples/indefinite.rs (line 36)
8async fn main() -> Result<(), PresenceError> {
9    let mut runner = PresenceRunner::new("1463450870480900160")
10        .on_ready(|data| {
11            println!(
12                "RPC version: v{}; Connected to user: {}",
13                data.version(),
14                data.user.global_name().unwrap_or_default(),
15            )
16        })
17        .on_activity_send(|data| {
18            println!(
19                "Activity sent to app! (running on {})\nCreated at: {}",
20                data.platform().unwrap_or_default(),
21                data.activity.created_at()
22            );
23        })
24        .on_disconnect(|f| println!("Disconnected: {f:?}"))
25        .show_errors() // enables verbose error logging
26        .on_retry(move |c| {
27            if c % 10 == 0 {
28                println!("Retry count {c}; is Discord open?");
29            }
30        });
31
32    let client = runner.run(true).await?;
33
34    // the activity can include any combination of builder function calls
35    let activity = Activity::new()
36        .activity_type(ActivityType::Playing)
37        .details("epic game")
38        .details_url("https://github.com/hitblast")
39        .status_display_type(StatusDisplayType::Details)
40        .large_image("game_icon")
41        .large_text("Playing a game")
42        .large_url("https://hitblast.github.io/")
43        .small_image("status")
44        .small_text("Online")
45        .build()?;
46
47    client.set_activity(activity).await?;
48
49    // indefinitely block here
50    runner.wait().await?;
51
52    Ok(())
53}
Source

pub fn set_as_instance(self) -> Self

Sets the activity to be an instance.

Source

pub fn status_display_type(self, type: StatusDisplayType) -> Self

The status display type for the activity.

Examples found in repository?
examples/indefinite.rs (line 39)
8async fn main() -> Result<(), PresenceError> {
9    let mut runner = PresenceRunner::new("1463450870480900160")
10        .on_ready(|data| {
11            println!(
12                "RPC version: v{}; Connected to user: {}",
13                data.version(),
14                data.user.global_name().unwrap_or_default(),
15            )
16        })
17        .on_activity_send(|data| {
18            println!(
19                "Activity sent to app! (running on {})\nCreated at: {}",
20                data.platform().unwrap_or_default(),
21                data.activity.created_at()
22            );
23        })
24        .on_disconnect(|f| println!("Disconnected: {f:?}"))
25        .show_errors() // enables verbose error logging
26        .on_retry(move |c| {
27            if c % 10 == 0 {
28                println!("Retry count {c}; is Discord open?");
29            }
30        });
31
32    let client = runner.run(true).await?;
33
34    // the activity can include any combination of builder function calls
35    let activity = Activity::new()
36        .activity_type(ActivityType::Playing)
37        .details("epic game")
38        .details_url("https://github.com/hitblast")
39        .status_display_type(StatusDisplayType::Details)
40        .large_image("game_icon")
41        .large_text("Playing a game")
42        .large_url("https://hitblast.github.io/")
43        .small_image("status")
44        .small_text("Online")
45        .build()?;
46
47    client.set_activity(activity).await?;
48
49    // indefinitely block here
50    runner.wait().await?;
51
52    Ok(())
53}
Source

pub fn duration(self, duration: Duration) -> Self

Countdown duration for your activity.

Examples found in repository?
examples/timed.rs (line 43)
13async fn main() -> Result<(), PresenceError> {
14    // simple atomic counter
15    let count = Arc::new(AtomicUsize::new(0));
16
17    let mut runner = PresenceRunner::new("1463450870480900160")
18        .on_ready(|data| println!("Connected to user: {}", data.user.username()))
19        .on_activity_send(move |_| {
20
21            // increments the counter with every send_activity()
22            let val = count.fetch_add(1, Ordering::Relaxed) + 1;
23
24            println!("Activity {val} sent successfully.")
25
26        })
27        .show_errors() // enables verbose error logging
28    ;
29
30    // create activities for later use
31    let activity_1 = Activity::new()
32        .details("this runs")
33        .state("for ten seconds")
34        .build()?;
35
36    let activity_2 = Activity::new()
37        .details("believe it")
38        .state("or not")
39        .build()?;
40
41    let closing_activity = Activity::new()
42        .details("closing presence in...")
43        .duration(Duration::from_secs(5))
44        .small_image("status")
45        .build()?;
46
47    // first run
48    let client = runner.run(true).await?;
49
50    client.set_activity(activity_1).await?;
51    sleep(Duration::from_secs(5)).await;
52    client.set_activity(activity_2).await?;
53    sleep(Duration::from_secs(5)).await;
54    client.set_activity(closing_activity).await?;
55    sleep(Duration::from_secs(5)).await;
56
57    client.close().await?;
58
59    println!("Stopped.");
60
61    Ok(())
62}
Source

pub fn add_button( self, label: impl Into<String>, url: impl Into<String>, ) -> Self

Adds a button to the activity.

NOTE: The Discord desktop client may behave in such a way that the buttons may only be visible from anyone but the connected user’s side. This is a wonky feature and must be used with care.

Source

pub fn build(self) -> Result<ActivitySpec, ActivitySpecBuildError>

Parses the state of this builder into a usable ActivitySpec for you to pass through crate::PresenceClient::set_activity.

Examples found in repository?
examples/simple.rs (line 11)
4async fn main() -> Result<(), PresenceError> {
5    let mut runner = PresenceRunner::new("1463450870480900160");
6
7    let activity = Activity::new()
8        .name("cool app name")
9        .details("Something?")
10        .state("Probably~")
11        .build()?;
12
13    let client = runner.run(true).await?;
14    client.set_activity(activity).await?;
15
16    // indefinitely block here
17    runner.wait().await?;
18
19    Ok(())
20}
More examples
Hide additional examples
examples/timed.rs (line 34)
13async fn main() -> Result<(), PresenceError> {
14    // simple atomic counter
15    let count = Arc::new(AtomicUsize::new(0));
16
17    let mut runner = PresenceRunner::new("1463450870480900160")
18        .on_ready(|data| println!("Connected to user: {}", data.user.username()))
19        .on_activity_send(move |_| {
20
21            // increments the counter with every send_activity()
22            let val = count.fetch_add(1, Ordering::Relaxed) + 1;
23
24            println!("Activity {val} sent successfully.")
25
26        })
27        .show_errors() // enables verbose error logging
28    ;
29
30    // create activities for later use
31    let activity_1 = Activity::new()
32        .details("this runs")
33        .state("for ten seconds")
34        .build()?;
35
36    let activity_2 = Activity::new()
37        .details("believe it")
38        .state("or not")
39        .build()?;
40
41    let closing_activity = Activity::new()
42        .details("closing presence in...")
43        .duration(Duration::from_secs(5))
44        .small_image("status")
45        .build()?;
46
47    // first run
48    let client = runner.run(true).await?;
49
50    client.set_activity(activity_1).await?;
51    sleep(Duration::from_secs(5)).await;
52    client.set_activity(activity_2).await?;
53    sleep(Duration::from_secs(5)).await;
54    client.set_activity(closing_activity).await?;
55    sleep(Duration::from_secs(5)).await;
56
57    client.close().await?;
58
59    println!("Stopped.");
60
61    Ok(())
62}
examples/indefinite.rs (line 45)
8async fn main() -> Result<(), PresenceError> {
9    let mut runner = PresenceRunner::new("1463450870480900160")
10        .on_ready(|data| {
11            println!(
12                "RPC version: v{}; Connected to user: {}",
13                data.version(),
14                data.user.global_name().unwrap_or_default(),
15            )
16        })
17        .on_activity_send(|data| {
18            println!(
19                "Activity sent to app! (running on {})\nCreated at: {}",
20                data.platform().unwrap_or_default(),
21                data.activity.created_at()
22            );
23        })
24        .on_disconnect(|f| println!("Disconnected: {f:?}"))
25        .show_errors() // enables verbose error logging
26        .on_retry(move |c| {
27            if c % 10 == 0 {
28                println!("Retry count {c}; is Discord open?");
29            }
30        });
31
32    let client = runner.run(true).await?;
33
34    // the activity can include any combination of builder function calls
35    let activity = Activity::new()
36        .activity_type(ActivityType::Playing)
37        .details("epic game")
38        .details_url("https://github.com/hitblast")
39        .status_display_type(StatusDisplayType::Details)
40        .large_image("game_icon")
41        .large_text("Playing a game")
42        .large_url("https://hitblast.github.io/")
43        .small_image("status")
44        .small_text("Online")
45        .build()?;
46
47    client.set_activity(activity).await?;
48
49    // indefinitely block here
50    runner.wait().await?;
51
52    Ok(())
53}

Trait Implementations§

Source§

impl Default for ActivityBuilder

Source§

fn default() -> ActivityBuilder

Returns the “default value” for a type. 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.