fluxion_core/
fluxion_item.rs

1// Copyright 2025 Umberto Gotti <umberto.gotti@umbertogotti.dev>
2// Licensed under the Apache License, Version 2.0
3// http://www.apache.org/licenses/LICENSE-2.0
4
5//! Base trait bounds for all Fluxion operators.
6//!
7//! This module defines [`FluxionItem`], which consolidates the minimal set
8//! of trait bounds required by all Fluxion operators.
9
10use crate::Timestamped;
11
12/// Base requirements for all Fluxion operators.
13///
14/// This trait represents the minimal set of bounds required by Fluxion operators.
15/// It combines timestamping, cloning, thread safety, and static lifetime requirements.
16///
17/// # Automatic Implementation
18///
19/// This trait is automatically implemented for any type that satisfies the bounds:
20///
21/// ```
22/// # use fluxion_core::{FluxionItem, Timestamped, HasTimestamp};
23/// # #[derive(Clone)]
24/// # struct MyType;
25/// # impl HasTimestamp for MyType {
26/// #     type Inner = MyType;
27/// #     type Timestamp = u64;
28/// #     fn timestamp(&self) -> u64 { 0 }
29/// # }
30/// # impl Timestamped for MyType {
31/// #     fn with_timestamp(value: Self::Inner, _: u64) -> Self { value }
32/// #     fn with_fresh_timestamp(value: Self::Inner) -> Self { value }
33/// #     fn into_inner(self) -> Self::Inner { self }
34/// # }
35/// // MyType automatically implements FluxionItem if it meets the bounds
36/// fn assert_fluxion_item<T: FluxionItem>() {}
37/// fn example() {
38///     assert_fluxion_item::<MyType>();
39/// }
40/// ```
41///
42/// # Usage
43///
44/// Use this trait bound for operators that only require basic functionality:
45///
46/// ```
47/// # use fluxion_core::{FluxionItem, StreamItem};
48/// # use futures::Stream;
49/// pub trait MyOperatorExt<T>: Stream<Item = StreamItem<T>>
50/// where
51///     T: FluxionItem,
52/// {
53///     // operator implementation
54/// }
55/// ```
56pub trait FluxionItem: Timestamped + Clone + Send + Sync + 'static {}
57
58/// Blanket implementation for all types that satisfy the base requirements.
59impl<T> FluxionItem for T where T: Timestamped + Clone + Send + Sync + 'static {}