hyveos_sdk/
lib.rs

1#![warn(clippy::pedantic, clippy::expect_used, clippy::unwrap_used)]
2#![allow(clippy::module_name_repetitions)]
3#![cfg_attr(docsrs, feature(doc_auto_cfg))]
4#![cfg_attr(docsrs, allow(unused_attributes))]
5
6//! # HyveOS SDK
7//!
8//! This crate provides a high-level API for interacting with the HyveOS runtime.
9//!
10//! > **Note**: By default, the [`Connection`] struct assumes that it's running inside a script docker container,
11//! > started by the HyveOS runtime.
12//! > To use the SDK elsewhere, the connection can be configured using [`ConnectionBuilder`].
13//!
14//! ## Crate Features
15//!
16//! - `json` - Enables JSON (de-)serialization for data exchanged with other nodes.
17//! - `cbor` - Enables CBOR (de-)serialization for data exchanged with other nodes.
18//!
19//! ## Example
20//!
21//! ```no_run
22//! use futures::StreamExt as _;
23//! use hyveos_sdk::Connection;
24//!
25//! #[tokio::main]
26//! async fn main() {
27//!     let connection = Connection::new().await.unwrap();
28//!     let mut dht_service = connection.dht();
29//!     let peer_id = dht_service
30//!         .get_providers("identification", "example")
31//!         .await
32//!         .unwrap()
33//!         .next()
34//!         .await
35//!         .unwrap()
36//!         .unwrap();
37//!
38//!     let mut req_resp_service = connection.req_resp();
39//!     let response = req_resp_service
40//!         .send_request(peer_id, "Hello, world!", None)
41//!         .await
42//!         .unwrap();
43//!
44//!     let data = Vec::try_from(response).unwrap();
45//!     println!("Received response: {}", String::from_utf8(data).unwrap());
46//! }
47//! ```
48
49#[cfg(feature = "network")]
50pub use http::Uri;
51pub use libp2p_identity::PeerId;
52
53#[doc(inline)]
54pub use crate::{
55    connection::{Connection, ConnectionBuilder},
56    error::Error,
57};
58
59pub mod connection;
60pub mod error;
61pub mod services;