async_osc/
lib.rs

1#![forbid(unsafe_code, future_incompatible, rust_2018_idioms)]
2#![deny(missing_debug_implementations, nonstandard_style)]
3#![warn(missing_docs, missing_doc_code_examples, unreachable_pub)]
4
5//! Async library for the Open Sound Control (OSC) protocol
6//!
7//! # Examples
8//!
9//! ```
10//! # #[async_std::main]
11//! # async fn main() -> async_osc::Result<()> {
12//! use async_std::stream::StreamExt;
13//! use async_osc::{prelude::*, OscSocket, OscPacket, OscType, Error, Result};
14//!
15//! let mut socket = OscSocket::bind("localhost:5050").await?;
16//!
17//! // Open a second socket to send a test message.
18//! async_std::task::spawn(async move {
19//!     let socket = OscSocket::bind("localhost:0").await?;
20//!     socket.connect("localhost:5050").await?;
21//!     socket.send(("/volume", (0.9f32,))).await?;
22//!     Ok::<(), Error>(())
23//! });
24//!
25//! // Listen for incoming packets on the first socket.
26//! while let Some(packet) = socket.next().await {
27//!     let (packet, peer_addr) = packet?;
28//!     eprintln!("Receive from {}: {:?}", peer_addr, packet);
29//!     match packet {
30//!         OscPacket::Bundle(_) => {}
31//!         OscPacket::Message(message) => match message.as_tuple() {
32//!             ("/volume", &[OscType::Float(vol)]) => {
33//!                 eprintln!("Set volume: {}", vol);
34//!                 // Do something with the received data.
35//!                 // Here, just quit the doctest.
36//!                 assert_eq!(vol, 0.9f32);
37//!                 return Ok(())
38//!             }
39//!             _ => {}
40//!         },
41//!     }
42//! }
43//! # Ok(())
44//! # }
45//! // tbi
46//! ```
47
48/// Re-export the main OSC types from the [`rosc`] crate.
49pub mod rosc {
50    pub use ::rosc::{OscBundle, OscMessage, OscPacket, OscType};
51}
52
53pub use crate::rosc::*;
54
55mod error;
56mod message;
57mod osc;
58mod udp;
59
60pub use error::{Error, Result};
61pub use osc::{OscSender, OscSocket};
62// pub use udp::*;
63
64/// Prelude with extensions to [`rosc`] types.
65///
66/// It is recommended to import everything from this module whenever working with these types.
67/// See [`preulude::OscMessageExt`] for details.
68pub mod prelude {
69    pub use crate::message::{
70        IntoOscArgs, IntoOscMessage, IntoOscPacket, OscMessageExt, OscPacketExt,
71    };
72}