feat: add message types to be sent over channels

This commit is contained in:
Callum Leslie 2025-09-02 16:22:20 +01:00
parent 1215e8ae74
commit b5a659f8a7
Signed by: cleslie
GPG key ID: D382C4AFEECEAA90
2 changed files with 30 additions and 0 deletions

View file

@ -1,3 +1,8 @@
#![doc = include_str!("../README.md")] #![doc = include_str!("../README.md")]
pub mod error; pub mod error;
pub mod types;
// Re-exports
pub use error::Error;
pub use types::ValueSource;

25
src/types.rs Normal file
View file

@ -0,0 +1,25 @@
/// Request messages sent from consumer to producer
pub enum Request {
GetValue,
Close,
}
/// Response messages sent from producer to consumer
pub enum Response<T> {
Value(T),
NoSource,
Closed,
}
/// Represents the source of values: either static or dynamic
pub enum ValueSource<T> {
Static(T),
Dynamic(Box<dyn Fn() -> T + Send + Sync + 'static>),
None,
}
/// Internal channel state shared between producer and consumer
pub struct ChannelState<T> {
pub source: ValueSource<T>,
pub closed: bool,
}