Skip to content

Commit 56980e3

Browse files
committed
MemoryStore -> impl Store
1 parent 606ed4b commit 56980e3

13 files changed

Lines changed: 100 additions & 91 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Node<WorkflowState> for ProcessorNode {
4141
type PrepResult = String;
4242
type ExecResult = bool;
4343

44-
async fn prep(&self, store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
44+
async fn prep(&self, store: &impl Store) -> Result<Self::PrepResult, CanoError> {
4545
let input: String = store.get("input").unwrap_or_default();
4646
Ok(input)
4747
}
@@ -51,7 +51,7 @@ impl Node<WorkflowState> for ProcessorNode {
5151
true // Success
5252
}
5353

54-
async fn post(&self, store: &MemoryStore, exec_res: Self::ExecResult)
54+
async fn post(&self, store: &impl Store, exec_res: Self::ExecResult)
5555
-> Result<WorkflowState, CanoError> {
5656
if exec_res {
5757
store.put("result", "processed".to_string())?;
@@ -110,7 +110,7 @@ impl Node<String> for EmailProcessor {
110110
type PrepResult = String;
111111
type ExecResult = bool;
112112

113-
async fn prep(&self, store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
113+
async fn prep(&self, store: &impl Store) -> Result<Self::PrepResult, CanoError> {
114114
// Load email data from store
115115
let email: String = store.get("email").unwrap_or_default();
116116
Ok(email)
@@ -122,7 +122,7 @@ impl Node<String> for EmailProcessor {
122122
true // Success
123123
}
124124

125-
async fn post(&self, store: &MemoryStore, success: Self::ExecResult)
125+
async fn post(&self, store: &impl Store, success: Self::ExecResult)
126126
-> Result<String, CanoError> {
127127
// Store the result and return next action
128128
if success {

benches/flow_performance.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use async_trait::async_trait;
2-
use cano::{CanoError, Flow, MemoryStore, Node};
2+
use cano::{CanoError, Flow, MemoryStore, Node, Store};
33
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
44

55
/// Simple do-nothing node for benchmarking
@@ -35,7 +35,7 @@ impl Node<TestState> for DoNothingNode {
3535
type PrepResult = ();
3636
type ExecResult = ();
3737

38-
async fn prep(&self, _store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
38+
async fn prep(&self, _store: &impl Store) -> Result<Self::PrepResult, CanoError> {
3939
Ok(())
4040
}
4141

@@ -46,7 +46,7 @@ impl Node<TestState> for DoNothingNode {
4646

4747
async fn post(
4848
&self,
49-
_store: &MemoryStore,
49+
_store: &impl Store,
5050
_exec_res: Self::ExecResult,
5151
) -> Result<TestState, CanoError> {
5252
Ok(self.next_state.clone())

benches/node_performance.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use async_trait::async_trait;
2-
use cano::store::StoreTrait;
2+
use cano::store::Store;
33
use cano::{CanoError, DefaultParams, MemoryStore, Node};
44
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
55

@@ -29,7 +29,7 @@ impl Node<TestState> for DoNothingNode {
2929
type PrepResult = ();
3030
type ExecResult = ();
3131

32-
async fn prep(&self, _store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
32+
async fn prep(&self, _store: &impl Store) -> Result<Self::PrepResult, CanoError> {
3333
Ok(())
3434
}
3535

@@ -40,7 +40,7 @@ impl Node<TestState> for DoNothingNode {
4040

4141
async fn post(
4242
&self,
43-
_store: &MemoryStore,
43+
_store: &impl Store,
4444
_exec_res: Self::ExecResult,
4545
) -> Result<TestState, CanoError> {
4646
Ok(self.next_state.clone())
@@ -68,7 +68,7 @@ impl Node<TestState> for CpuIntensiveNode {
6868
type PrepResult = Vec<u64>;
6969
type ExecResult = u64;
7070

71-
async fn prep(&self, _store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
71+
async fn prep(&self, _store: &impl Store) -> Result<Self::PrepResult, CanoError> {
7272
// Generate some data to process
7373
Ok((0..self.iterations as u64).collect())
7474
}
@@ -80,7 +80,7 @@ impl Node<TestState> for CpuIntensiveNode {
8080

8181
async fn post(
8282
&self,
83-
store: &MemoryStore,
83+
store: &impl Store,
8484
exec_res: Self::ExecResult,
8585
) -> Result<TestState, CanoError> {
8686
// Store the result
@@ -110,7 +110,7 @@ impl Node<TestState> for IoSimulationNode {
110110
type PrepResult = String;
111111
type ExecResult = String;
112112

113-
async fn prep(&self, _store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
113+
async fn prep(&self, _store: &impl Store) -> Result<Self::PrepResult, CanoError> {
114114
// Simulate I/O delay
115115
tokio::time::sleep(tokio::time::Duration::from_millis(self.delay_ms)).await;
116116
Ok("prepared_data".to_string())
@@ -124,7 +124,7 @@ impl Node<TestState> for IoSimulationNode {
124124

125125
async fn post(
126126
&self,
127-
store: &MemoryStore,
127+
store: &impl Store,
128128
exec_res: Self::ExecResult,
129129
) -> Result<TestState, CanoError> {
130130
// Simulate I/O delay

benches/store_performance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cano::{MemoryStore, store::StoreTrait};
1+
use cano::{MemoryStore, store::Store};
22
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
33

44
fn bench_storage_operations(c: &mut Criterion) {

examples/book_prepositions.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use async_trait::async_trait;
2424
use cano::error::CanoError;
2525
use cano::prelude::*;
26-
use cano::store::{MemoryStore, StoreTrait};
26+
use cano::store::{MemoryStore, Store};
2727
use futures::future::join_all;
2828
use std::collections::{HashMap, HashSet};
2929
use tokio::time::{Duration, timeout};
@@ -275,7 +275,7 @@ impl Node<BookPrepositionAction> for BookDownloaderNode {
275275
}
276276

277277
/// Preparation: Get the list of books to download
278-
async fn prep(&self, _store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
278+
async fn prep(&self, _store: &impl Store) -> Result<Self::PrepResult, CanoError> {
279279
let book_list = Self::get_book_list();
280280
println!("📋 Prepared {} books for download", book_list.len());
281281
Ok(book_list)
@@ -322,7 +322,7 @@ impl Node<BookPrepositionAction> for BookDownloaderNode {
322322
/// Post-processing: Store downloaded books in memory
323323
async fn post(
324324
&self,
325-
store: &MemoryStore,
325+
store: &impl Store,
326326
exec_res: Self::ExecResult,
327327
) -> Result<BookPrepositionAction, CanoError> {
328328
if exec_res.is_empty() {
@@ -415,7 +415,7 @@ impl Node<BookPrepositionAction> for PrepositionNode {
415415
}
416416

417417
/// Preparation: Load downloaded books from memory
418-
async fn prep(&self, store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
418+
async fn prep(&self, store: &impl Store) -> Result<Self::PrepResult, CanoError> {
419419
let books: Vec<Book> = store
420420
.get("downloaded_books")
421421
.map_err(|e| CanoError::preparation(format!("Failed to load books: {e}")))?;
@@ -454,7 +454,7 @@ impl Node<BookPrepositionAction> for PrepositionNode {
454454
/// Post-processing: Store analysis results
455455
async fn post(
456456
&self,
457-
store: &MemoryStore,
457+
store: &impl Store,
458458
exec_res: Self::ExecResult,
459459
) -> Result<BookPrepositionAction, CanoError> {
460460
if exec_res.is_empty() {
@@ -501,7 +501,7 @@ impl Node<BookPrepositionAction> for BookRankingByPrepositionNode {
501501
}
502502

503503
/// Preparation: Load book analyses from memory
504-
async fn prep(&self, store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
504+
async fn prep(&self, store: &impl Store) -> Result<Self::PrepResult, CanoError> {
505505
let analyses: Vec<BookAnalysis> = store
506506
.get("book_analyses")
507507
.map_err(|e| CanoError::preparation(format!("Failed to load analyses: {e}")))?;
@@ -545,7 +545,7 @@ impl Node<BookPrepositionAction> for BookRankingByPrepositionNode {
545545
/// Post-processing: Store final rankings and display results
546546
async fn post(
547547
&self,
548-
store: &MemoryStore,
548+
store: &impl Store,
549549
exec_res: Self::ExecResult,
550550
) -> Result<BookPrepositionAction, CanoError> {
551551
store.put("book_rankings", exec_res.clone())?;
@@ -711,7 +711,7 @@ async fn main() {
711711
#[cfg(test)]
712712
mod tests {
713713
use super::*;
714-
use cano::store::{MemoryStore, StoreTrait};
714+
use cano::store::{MemoryStore, Store};
715715

716716
#[tokio::test]
717717
async fn test_book_downloader_prep() {

examples/negotiation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl Node<NegotiationAction> for SellerNode {
8989
}
9090

9191
/// Preparation phase: Load current negotiation state or initialize if first round
92-
async fn prep(&self, store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
92+
async fn prep(&self, store: &impl Store) -> Result<Self::PrepResult, CanoError> {
9393
match store.get::<NegotiationState>("negotiation_state") {
9494
Ok(state) => {
9595
println!(
@@ -146,7 +146,7 @@ impl Node<NegotiationAction> for SellerNode {
146146
/// Post-processing phase: Store the updated offer for buyer evaluation
147147
async fn post(
148148
&self,
149-
store: &MemoryStore,
149+
store: &impl Store,
150150
exec_res: Self::ExecResult,
151151
) -> Result<NegotiationAction, CanoError> {
152152
// Store the current negotiation state
@@ -204,7 +204,7 @@ impl Node<NegotiationAction> for BuyerNode {
204204
}
205205

206206
/// Preparation phase: Load the current negotiation state
207-
async fn prep(&self, store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
207+
async fn prep(&self, store: &impl Store) -> Result<Self::PrepResult, CanoError> {
208208
let state: NegotiationState = store.get("negotiation_state").map_err(|e| {
209209
CanoError::preparation(format!("Failed to load negotiation state: {e}"))
210210
})?;
@@ -254,7 +254,7 @@ impl Node<NegotiationAction> for BuyerNode {
254254
/// Post-processing phase: Update state and determine next action
255255
async fn post(
256256
&self,
257-
store: &MemoryStore,
257+
store: &impl Store,
258258
exec_res: Self::ExecResult,
259259
) -> Result<NegotiationAction, CanoError> {
260260
let (mut state, acceptable) = exec_res;

examples/simple.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Node<WorkflowAction> for GeneratorNode {
5454
}
5555

5656
/// Preparation phase: Generate a random vector of u32 numbers (25 to 150 elements)
57-
async fn prep(&self, _store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
57+
async fn prep(&self, _store: &impl Store) -> Result<Self::PrepResult, CanoError> {
5858
let mut rng = rand::rng();
5959

6060
// Generate random size between 25 and 150
@@ -85,7 +85,7 @@ impl Node<WorkflowAction> for GeneratorNode {
8585
/// Post-processing phase: Store the filtered vector in memory
8686
async fn post(
8787
&self,
88-
store: &MemoryStore,
88+
store: &impl Store,
8989
exec_res: Self::ExecResult,
9090
) -> Result<WorkflowAction, CanoError> {
9191
// Store the filtered vector in memory
@@ -125,7 +125,7 @@ impl Node<WorkflowAction> for CounterNode {
125125
}
126126

127127
/// Preparation phase: Load the filtered numbers from memory
128-
async fn prep(&self, store: &MemoryStore) -> Result<Self::PrepResult, CanoError> {
128+
async fn prep(&self, store: &impl Store) -> Result<Self::PrepResult, CanoError> {
129129
let numbers: Vec<u32> = store
130130
.get("filtered_numbers")
131131
.map_err(|e| CanoError::preparation(format!("Failed to load filtered numbers: {e}")))?;
@@ -147,7 +147,7 @@ impl Node<WorkflowAction> for CounterNode {
147147
/// Post-processing phase: Store count and clean up the original vector
148148
async fn post(
149149
&self,
150-
store: &MemoryStore,
150+
store: &impl Store,
151151
exec_res: Self::ExecResult,
152152
) -> Result<WorkflowAction, CanoError> {
153153
// Store the count

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
//! This means store operations can seamlessly flow into the broader error system:
4343
//!
4444
//! ```rust
45-
//! use cano::{CanoResult, store::MemoryStore, store::StoreTrait};
45+
//! use cano::{CanoResult, store::MemoryStore, store::Store};
4646
//!
4747
//! fn example_function() -> CanoResult<String> {
4848
//! let store = MemoryStore::new();

0 commit comments

Comments
 (0)