summaryrefslogtreecommitdiffstats
path: root/examples/log_events.rs
blob: 8858f4d42b8a2a2ec27435f4d963bed11cb98b9e (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
45
46
47
#![cfg_attr(not(feature = "toml"), allow(dead_code))]
#![cfg_attr(not(feature = "toml"), allow(unused_imports))]
mod register;

use futures_util::TryStreamExt;
use log::{as_serde, info};
use mastodon_async::Result;

#[cfg(feature = "toml")]
async fn run() -> Result<()> {
    use log::warn;

    femme::with_level(log::LevelFilter::Info);
    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 {
            match event {
                // fill in how you want to handle events here.
                _ => warn!(event = as_serde!(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"
    );
}