fauna-api 1.0.800

The Fauna SDK for Rust: accounts, Drive, groups, calendar, chats, payments, Parrot and live rooms.
Documentation
//! Rust mirror of the `fauna-api` SDK in `api/node`. Every public item here
//! matches an export there; `npm run sdk:parity` checks the two stay in sync.

mod error;
mod http;
mod route;

pub mod ant;
pub mod authentification;
pub mod billing;
pub mod calendar;
pub mod chats;
pub mod cicada;
pub mod drive;
pub mod extensions;
pub mod friends;
pub mod groups;
pub mod inbox;
pub mod integrations;
pub mod magpie;
pub mod maps;
pub mod marmot;
pub mod parrot;
pub mod payments;
#[doc(hidden)]
pub mod private;
pub mod rooms;
pub mod shared;
pub mod termite;
pub mod tickets;
pub mod travel;
pub mod view;
pub mod webhooks;

use std::future::Future;
use std::time::Instant;

use futures_util::StreamExt;
use futures_util::stream;

pub use error::{Error, Result};

static ROUTE: route::Cell = route::cell();

pub fn set_route(route: &str) {
    route::set(&ROUTE, route);
}

pub fn get_ip() -> String {
    route::ip(&ROUTE)
}

pub fn get_port() -> u16 {
    route::port(&ROUTE)
}

pub fn get_route() -> String {
    route::route(&ROUTE)
}

pub fn get_url() -> String {
    route::url(&ROUTE)
}

/// Milliseconds for one round trip to the gateway root.
pub async fn ping() -> Result<u64> {
    let start = Instant::now();
    http::client().get(format!("{}/", get_url())).send().await?;
    Ok(start.elapsed().as_millis() as u64)
}

pub use shared::server as live;

pub use shared::schema::Schema;

/// Runs `tasks` with at most `max` in flight and returns their results in task order.
pub async fn throttling_promise<T, F, Fut>(tasks: Vec<F>, max: usize) -> Vec<T>
where
    F: FnOnce() -> Fut,
    Fut: Future<Output = T>,
{
    if max == 0 {
        return Vec::new();
    }
    stream::iter(tasks.into_iter().map(|task| task()))
        .buffered(max)
        .collect()
        .await
}