4 个版本

0.1.5 2023年7月6日
0.1.3 2023年7月4日
0.1.1 2023年7月4日
0.1.0 2023年7月3日

#4#hackernews 分类中

MIT/Apache

21KB
280

hacker-rs

Hacker News API 绑定库。

use hacker_rs::client::HackerNewsClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Build your client at the start of your application process
    let client = HackerNewsClient::new();

    // Call various endpoints with your client instance
    let first_item = client.get_item(69).await?;
    dbg!(&first_item);

    // Determine what the item type is
    let item_type = first_item.get_item_type();
    dbg!(item_type);

    // Check if the item is job
    assert!(first_item.is_comment());

    // Retrieve user information
    let user = client.get_user("joeymckenzie").await;
    dbg!(user);

    Ok(())
}

lib.rs:

Hacker News API 绑定库。

let client = HackerNewsClient::new();

// Call various endpoints with your client instance
let first_item = client.get_item(69).await?;
dbg!(&first_item);

// Determine what the item type is
let item_type = first_item.get_item_type();
dbg!(item_type);

// Check if the item is job
assert!(first_item.is_comment());

// Retrieve user information
let user = client.get_user("joeymckenzie").await?;
dbg!(user);

依赖

~4–19MB
~257K SLoC