hacker_rs/lib.rs
1//! [Hacker News](https://news.ycombinator.com/) API bindings for Rust.
2//!
3//! ```compile_fail
4//! let client = HackerNewsClient::new();
5//!
6//! // Call various endpoints with your client instance
7//! let first_item = client.get_item(69).await?;
8//! dbg!(&first_item);
9//!
10//! // Determine what the item type is
11//! let item_type = first_item.get_item_type();
12//! dbg!(item_type);
13//!
14//! // Check if the item is job
15//! assert!(first_item.is_comment());
16//!
17//! // Retrieve user information
18//! let user = client.get_user("joeymckenzie").await?;
19//! dbg!(user);
20//! ```
21
22#![feature(type_alias_impl_trait)]
23#![forbid(unsafe_code, dead_code)]
24#![warn(
25 missing_docs,
26 missing_debug_implementations,
27 missing_copy_implementations,
28 trivial_casts,
29 unused_allocation,
30 trivial_numeric_casts,
31 clippy::single_char_pattern
32)]
33
34pub mod client;
35pub mod comments;
36pub mod errors;
37pub mod items;
38pub mod stories;
39pub mod users;
40
41/// The ID associated to all Hacker News items and users.
42type HackerNewsID = u32;
43
44/// Current URL of the API.
45pub const API_BASE_URL: &str = "https://hacker-news.firebaseio.com";
46
47/// Item endpoint for stories, polls, news items, etc.
48pub const ITEM_ENDPOINT: &str = "item";
49
50/// User endpoint for user data and related items.
51pub const USERS_ENDPOINT: &str = "user";
52
53/// Default timeout for requests the API.
54pub const DEFAULT_TIMEOUT_SECONDS: u64 = 10;