Skip to content

Conversation

konard
Copy link
Member

@konard konard commented Sep 11, 2025

Summary

This PR implements the HandlerResult trait as suggested in issue #4, eliminating the need for unnecessary trailing Flow::Continue returns in handlers.

Problem

Currently, every handler must return Try<Output = ()>, which requires explicit Flow::Continue returns even when handlers just perform some action and want to continue:

// Before: Unnecessary boilerplate :(
links.each(|link| {
    worker.work(link);
    Flow::Continue // <- Annoying!
});

Solution

The new HandlerResult trait allows handlers to return either () (implying Flow::Continue) or explicit Flow/Try types:

// After: No boilerplate needed! :)
links.each(|link| {
    worker.work(link);
    // Implicit continue - no trailing Flow::Continue needed!
});

Implementation Details

  • HandlerResult trait: Converts various return types to Try<Output = ()>

    • ()Flow::Continue (the main benefit)
    • FlowFlow (backward compatibility)
    • Any Try<Output = ()> → itself (extensibility)
  • Updated trait methods: All each_*, create_*, update_*, and delete_* methods now accept HandlerResult instead of Try<Output = ()>

  • Backward compatibility: Existing code with explicit Flow returns continues to work

Benefits

Eliminates boilerplate: No more unnecessary Flow::Continue returns
Backward compatible: Existing handlers with explicit Flow returns still work
Type-safe: Compile-time guarantees about handler return types
Flexible: Supports mixed usage patterns in the same codebase

Test Plan

  • Created comprehensive examples demonstrating the new API
  • Verified both () and explicit Flow returns work correctly
  • Confirmed backward compatibility with existing patterns

Example Usage

The example in examples/handler_result_demo.rs demonstrates the improvement:

// New simplified API - the main benefit!
links.each(|link| {
    worker.work(link);
    // No trailing Flow::Continue needed!
});

// Explicit control flow still works when needed
links.each(|link| {
    process(link);
    if should_stop(link) {
        Flow::Break
    } else {
        // Can use () instead of Flow::Continue
    }
});

Fixes #4

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #4
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 14:04
…:Continue

This commit implements the HandlerResult trait as suggested in issue #4,
allowing handlers to return () instead of requiring explicit Flow::Continue.

## Changes:

- Added HandlerResult trait in handler.rs with implementations for () and Try types
- Updated all trait methods in traits.rs to use HandlerResult instead of Try<Output = ()>
- Modified Handler trait and Fuse struct to work with HandlerResult
- Added example demonstrating the new API

## Benefits:

- Eliminates unnecessary trailing Flow::Continue in simple handlers
- Maintains backward compatibility with explicit Flow returns
- Reduces boilerplate code as requested in issue #4

## Example usage:

### Before:
```rust
links.each(|link| {
    worker.work(link);
    Flow::Continue // <- Unnecessary boilerplate
});
```

### After:
```rust
links.each(|link| {
    worker.work(link);
    // No trailing Flow::Continue needed!
});
```

Fixes #4

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Unnecessary trailing Flow::Continue Implement HandlerResult trait to eliminate unnecessary trailing Flow::Continue Sep 11, 2025
@konard konard marked this pull request as ready for review September 11, 2025 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnecessary trailing Flow::Continue

1 participant