Skip to main content

grabcli_core/
lib.rs

1//! Shared core for grabcli: the parts every Grab service reuses — config,
2//! session, auth/hydra, the allowlisted HTTP client, the read-only response
3//! cache and money helpers.
4//!
5//! The library owns no storage and reads no files or environment: an
6//! embedder builds a [`Context`] with [`Context::new`]`(config, session_store,
7//! cache)`, passing an `Arc<dyn` [`SessionStore`]`>` and an `Arc<dyn`
8//! [`Cache`]`>`. The `grab` CLI uses a `session.json` file store and the
9//! SQLite cache from `grabcli-sqlite`; a daemon can back both with its own
10//! database. Service crates (e.g. `grabfood`) register their URL allowlist
11//! and make calls through the context.
12//!
13//! # Example: format a price
14//!
15//! ```
16//! use grabcli_core::Money;
17//!
18//! let price = Money(12_345); // integer centavos, not floating-point pesos
19//! assert_eq!(price.peso(), "₱123.45");
20//! assert_eq!(price.minor(), 12_345);
21//! ```
22//!
23//! For HTTP calls, construct a [`Context`] with your own [`SessionStore`] and
24//! [`Cache`]; see `grabfood::context` or `grabcli-service` for service-level setup.
25
26pub mod cache;
27pub mod cdp;
28pub mod config;
29pub mod ctx;
30pub mod error;
31pub mod http;
32pub mod hydra;
33pub mod jwt;
34pub mod location;
35pub mod login;
36pub mod money;
37pub mod places;
38pub mod session;
39pub mod sso;
40pub mod store;
41
42pub use cache::{Cache, CacheHandle, CacheKey, CacheKind, CacheMode, Fetched};
43pub use config::Config;
44pub use ctx::Context;
45pub use error::{Error, ErrorKind, Result};
46pub use http::{Allowlist, Client, Hydra, Request};
47pub use location::Location;
48pub use money::Money;
49pub use session::Session;
50pub use store::{MemorySessionStore, SessionStore};
51
52/// Package README examples, compiled as doctests.
53#[cfg(doctest)]
54#[doc = include_str!("../README.md")]
55struct ReadmeDoctests;