Skip to main content
QAROS Rust API Dev (main) · versions: Dev (main) · Developer Guide

qaros/
lib.rs

1//! Safe Rust API over the QAROS streaming C API.
2//!
3//! Covers what a streaming application needs: loading and initializing the
4//! library, the loaded runtime's version, runtimes, onboarding and rejoin,
5//! blocking or async (pairing code, remote hub, co-process invites, local app
6//! approved in the hub, app tags, remote-app grants, a declared device, adapter
7//! choice, planned peer id, re-enrollment), member hubs, peers, the CPU render sender, the
8//! Vulkan render sender (feature `vulkan`, module `vulkan`), the D3D11 render
9//! sender (feature `d3d11`, module `d3d11`: Windows; on macOS only for the
10//! tests against `qaros-stub`), app volumes and GUI panels. Hands, gestures and world anchors
11//! stay in [`qaros_sys`]; reach them, and every other raw call, through
12//! [`Library::raw_api`].
13//!
14//! # Design
15//!
16//! - Every fallible call returns [`Result`]; C errors carry the
17//!   [`StatusCode`] and the message from `qar_result_message`.
18//! - Init structures are built from the ported `qar_*_default()`
19//!   initializers, so every `QarStructureHeader` is stamped.
20//! - Handles release themselves on drop, and each keeps its parent alive, so
21//!   the C teardown order is always render sender, session, runtime,
22//!   library, whatever order Rust drops them in.
23//! - None of the handle types is `Send`: the SDK is designed for
24//!   single-threaded use per runtime, and callbacks are its only
25//!   cross-thread surface.
26//! - Subscription callbacks run on library threads. They receive owned
27//!   snapshots read from the borrowed C handle during the callback; use
28//!   [`channel`] to forward them into a `std::sync::mpsc` receiver. Their
29//!   state lives until the session is destroyed; a [`Subscription`] guard
30//!   only cancels.
31//!
32//! ```no_run
33//! use qaros::{BlockingOptions, Library, LibraryConfig, OnboardMethod, PeerPresentation, RuntimeConfig};
34//!
35//! # fn main() -> qaros::Result<()> {
36//! // SAFETY: the runtime found (the installed QAROS, or that of the instance QAR_INSTANCE
37//! // names) matches these bindings.
38//! let library = unsafe { Library::load_default(&LibraryConfig::default())? };
39//! let runtime = library.create_runtime(&RuntimeConfig::default())?;
40//! // An app on the hub's PC joins as a local app: the first start waits for Allow in QAROS.
41//! let onboarded = runtime.onboard(
42//!     &OnboardMethod::LocalApp { approval_timeout: None, app_tag: None },
43//!     &PeerPresentation::default(),
44//!     &BlockingOptions::default(),
45//! )?;
46//! let peers = onboarded.session.peers()?;
47//! # let _ = peers;
48//! # Ok(()) }
49//! ```
50
51mod adapter;
52mod callbacks;
53mod cancel;
54#[cfg(qaros_d3d11)]
55pub mod d3d11;
56mod device;
57mod error;
58mod invite;
59mod library;
60mod member_hub;
61mod panel_content;
62mod panels;
63mod peers;
64mod pending;
65mod pending_sender;
66mod render;
67mod runtime;
68mod session;
69mod strings;
70mod types;
71mod volumes;
72#[cfg(feature = "vulkan")]
73pub mod vulkan;
74
75pub use adapter::GraphicsAdapter;
76pub use callbacks::{BlockingOptions, Progress, channel};
77pub use cancel::{CancelHandle, CancelToken};
78pub use device::{
79    DeviceCategory, DeviceIdentity, PeerIdentity, PeerPresence, PeerRole, SourceDeviceCategory,
80};
81pub use error::{Error, Result, StatusCode};
82pub use invite::OnboardingInvite;
83pub use library::{Library, LibraryConfig, RuntimeInfo, TargetDevice};
84pub use member_hub::{
85    JoinHubAsMemberConfig, MemberHubInvitation, MemberHubInvitationConfig, MemberHubPermissions,
86};
87pub use panel_content::{
88    GuiPanelServedContent, PANEL_CONTENT_BUNDLE_NAME_MAX, PanelContent, PanelContentBundleId,
89    PanelContentFile, PanelContentMessage,
90};
91pub use panels::{GuiPanelConfig, GuiPanelInfo, GuiPanelSize, GuiPanels};
92pub use peers::PeerInfo;
93pub use pending::{PendingCall, PendingOnboard};
94pub use pending_sender::PendingRenderSender;
95pub use render::PendingFrame;
96pub use render::{
97    ColorAlphaMode, ColorEncoding, CpuFrame, CpuTexture, Frame, FrameViewSpec, OwnedFrame,
98    RenderLoop, RenderRequest, RenderSender, RenderSenderConfig, ShowParams, TextureSize,
99    VideoFrameLayout, VideoFrameView, ViewPose,
100};
101#[allow(deprecated)] // kept exported while deprecated
102pub use runtime::HubAddress;
103pub use runtime::{
104    OnboardExtensions, OnboardMethod, Onboarded, PeerPresentation, Runtime, RuntimeConfig,
105};
106pub use session::{Session, Subscription};
107pub use types::{
108    ActionSeverity, AppState, AppVolumeId, AppVolumeLifetime, Eye, Fov, FrameLayout,
109    GuiPanelContentType, GuiPanelId, GuiPanelState, LogSeverity, OnboardingId, PeerId, PixelFormat,
110    Pose, QarosDeviceKind, QarosView, Quat, SessionChangeCause, SessionId, SessionLifecycle,
111    SessionLifecycleState, StreamId, Vec3, ViewKind,
112};
113pub use volumes::{AppVolumeConfig, AppVolumeInfo, AppVolumeSize, AppVolumes};
114
115pub use qaros_sys;
116pub use qaros_sys::{installed_bin_folder, instance_runtime_folder, requested_instance};
117
118/// The binding's README as doc tests, so its "Use" example keeps compiling against the API.
119#[cfg(doctest)]
120#[doc = include_str!("../../../README.md")]
121struct ReadmeDocTests;