-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser.rs
41 lines (35 loc) · 1.11 KB
/
user.rs
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
use pastemyst::user::*;
#[tokio::main]
async fn main() -> UserResult<()> {
// Get a user.
tokio::task::spawn_blocking(||call_get_user().unwrap());
call_get_user_async().await?;
// Check if a user exists.
tokio::task::spawn_blocking(||call_user_exists().unwrap());
call_user_exists_async().await?;
Ok(())
}
fn call_user_exists() -> UserResult<()> {
const USERNAME: &str = "ANF-Studios";
let exists: bool = user_exists(USERNAME)?;
println!("The user '{}' exists: {}", USERNAME, exists);
Ok(())
}
async fn call_user_exists_async() -> UserResult<()> {
const USERNAME: &str = "ANF-Studios";
let exists: bool = user_exists_async(USERNAME).await?;
println!("The user '{}' exists: {}", USERNAME, exists);
Ok(())
}
fn call_get_user() -> UserResult<()> {
const USERNAME: &str = "ANF-Studios";
let user = get_user(USERNAME)?;
println!("{}", user.publicProfile);
Ok(())
}
async fn call_get_user_async() -> UserResult<()> {
const USERNAME: &str = "ANF-Studios";
let user = get_user_async(USERNAME).await?;
println!("{}", user.publicProfile);
Ok(())
}