streamdeck_oxide/navigation.rs
1//! Navigation traits and utilities for Stream Deck applications.
2//!
3//! This module provides traits and utilities for navigating between
4//! different views in a Stream Deck application.
5
6use crate::view::View;
7use generic_array::ArrayLength;
8
9type GetViewResult<W, H, C, N> = Result<Box<dyn View<W, H, C, N>>, Box<dyn std::error::Error>>;
10
11/// A trait for navigation entries in a Stream Deck application.
12///
13/// This trait is implemented by types that represent different views
14/// or screens in a Stream Deck application. It provides a method for
15/// getting the view associated with a navigation entry.
16pub trait NavigationEntry<W, H, C>: Default + Send + Sync + Clone + PartialEq + 'static
17where
18 W: ArrayLength,
19 H: ArrayLength,
20 C: Send + Clone + Sync + 'static,
21{
22 /// Get the view associated with this navigation entry.
23 ///
24 /// This method returns a boxed view that can be used to render
25 /// the buttons for this navigation entry.
26 fn get_view(
27 &self,
28 context: C,
29 ) -> impl std::future::Future<Output = GetViewResult<W, H, C, Self>>;
30}
31
32/// A helper trait for creating navigation entries.
33///
34/// This trait provides a method for creating a navigation entry
35/// with a specific view.
36pub trait IntoNavigationEntry<W, H, C, N>
37where
38 W: ArrayLength,
39 H: ArrayLength,
40 C: Send + Clone + Sync + 'static,
41 N: NavigationEntry<W, H, C>,
42{
43 /// Convert this type into a navigation entry.
44 fn into_navigation_entry(self) -> N;
45}