mirror of
https://github.com/callumio/suck.git
synced 2025-12-17 03:29:21 +00:00
feat: add message types to be sent over channels
This commit is contained in:
parent
1215e8ae74
commit
b5a659f8a7
2 changed files with 30 additions and 0 deletions
|
|
@ -1,3 +1,8 @@
|
|||
#![doc = include_str!("../README.md")]
|
||||
|
||||
pub mod error;
|
||||
pub mod types;
|
||||
|
||||
// Re-exports
|
||||
pub use error::Error;
|
||||
pub use types::ValueSource;
|
||||
|
|
|
|||
25
src/types.rs
Normal file
25
src/types.rs
Normal 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,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue