Skip to content

Conversation

@JustForFun88
Copy link
Contributor

@JustForFun88 JustForFun88 commented Jun 21, 2025

Summary

This PR hides the internals of the Ring<T> type and reworks its API. Direct access to the internal VecDeque<T> is removed, so interaction with Ring now happens only through its methods, making it easier and safer to use.

All lock-respecting insert/remove/swap logic is implemented directly on Ring and the separate LockableSequence trait removed.

The new API is more ergonomic and expressive for common patterns. As a result, although many new methods were added to Ring in komorebi/src/ring.rs, the total code size increased only slightly, since many typical iterator chains are now replaced by single method calls.

Motivation

  • Prevents accidental misuse by hiding internal collections and providing a clear, uniform API.
  • Enables future refactoring or switching to another implementation without breaking external code.

Usability Improvements

  • Consistent Access: Field and accessor now always return Ring, eliminating confusion between types (e.g., &monitor.workspaces vs monitor.workspaces()).

    // Before: different types, easy to misuse
    &monitor.workspaces     // &Ring<Workspace>
    monitor.workspaces()    // &VecDeque<Workspace>
    
    // After: always &Ring<Workspace>
    &monitor.workspaces
    monitor.workspaces()
  • Ergonomic usage: The new API is more ergonomic and expressive for common patterns

    monitors.indexed()            // replaces monitors.elements().iter().enumerate()
    monitors.position(..)         // replaces monitors.elements().iter().position(..)
    ws.floating_windows().any(..) // replaces ws.floating_windows().iter().any(..)

Tests

Tested on Windows 11.

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.

1 participant