summaryrefslogtreecommitdiffstats
path: root/examples/log_events.rs
blob: 137d6e5df7bba0e3498e90371e56c57bba3cc4ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#![cfg_attr(not(feature = "toml"), allow(dead_code))]
#![cfg_attr(not(feature = "toml"), allow(unused_imports))]
mod register;

use futures_util::TryStreamExt;
use mastodon_async::Result;
use tracing::{info, warn};

#[cfg(feature = "toml")]
async fn run() -> Result<()> {
    tracing_subscriber::fmt::init();
    let mastodon = register::get_mastodon_data().await?;
    let stream = mastodon.stream_user().await?;
    info!("watching mastodon for events. This will run forever, press Ctrl+C to kill the program.");
    stream
        .try_for_each(|(event, _client)| async move {
            // add a "match event {}" statement here to handle the different
            // kinds of events.
            warn!(?event, "unrecognized event received");
            Ok(())
        })
        .await?;
    Ok(())
}

#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
    run().await
}

#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
    run().await
}

#[cfg(not(feature = "toml"))]
fn main() {
    println!(
        "examples require the `toml` feature, run this command for this example:\n\ncargo run \
         --example log_events --features toml\n"
    );
}