Skip to main content

fauna_api/
lib.rs

1//! Rust mirror of the `fauna-api` SDK in `api/node`. Every public item here
2//! matches an export there; `npm run sdk:parity` checks the two stay in sync.
3
4mod error;
5mod http;
6mod route;
7
8pub mod authentification;
9pub mod billing;
10pub mod calendar;
11pub mod chats;
12pub mod drive;
13pub mod friends;
14pub mod groups;
15pub mod inbox;
16pub mod integrations;
17pub mod maps;
18pub mod parrot;
19pub mod payments;
20#[doc(hidden)]
21pub mod private;
22pub mod rooms;
23pub mod shared;
24pub mod tickets;
25pub mod travel;
26pub mod webhooks;
27
28use std::future::Future;
29use std::time::Instant;
30
31use futures_util::StreamExt;
32use futures_util::stream;
33
34pub use error::{Error, Result};
35
36static ROUTE: route::Cell = route::cell();
37
38pub fn set_route(route: &str) {
39    route::set(&ROUTE, route);
40}
41
42pub fn get_ip() -> String {
43    route::ip(&ROUTE)
44}
45
46pub fn get_port() -> u16 {
47    route::port(&ROUTE)
48}
49
50pub fn get_route() -> String {
51    route::route(&ROUTE)
52}
53
54pub fn get_url() -> String {
55    route::url(&ROUTE)
56}
57
58/// Milliseconds for one round trip to the gateway root.
59pub async fn ping() -> Result<u64> {
60    let start = Instant::now();
61    http::client().get(format!("{}/", get_url())).send().await?;
62    Ok(start.elapsed().as_millis() as u64)
63}
64
65pub use shared::server as live;
66
67pub use shared::schema::Schema;
68
69/// Runs `tasks` with at most `max` in flight and returns their results in task order.
70pub async fn throttling_promise<T, F, Fut>(tasks: Vec<F>, max: usize) -> Vec<T>
71where
72    F: FnOnce() -> Fut,
73    Fut: Future<Output = T>,
74{
75    if max == 0 {
76        return Vec::new();
77    }
78    stream::iter(tasks.into_iter().map(|task| task()))
79        .buffered(max)
80        .collect()
81        .await
82}