Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: deprecate Buffer::get and get_mut #1123

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Conversation

joshka
Copy link
Member

@joshka joshka commented May 21, 2024

Fixes: #1122

joshka added 8 commits May 2, 2024 18:20
Code which previously called `buf.get(x, y)` or `buf.get_mut(x, y)` can
now use index operators, or be transitioned to `buf_get_opt` or
`buf.get_mut_opt` for safe access that avoids panics.

The new methods accept `Into<Position>` instead of `x` and `y`
coordinates, which makes them more ergonomic to use.

```rust
let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10));

let cell = buf[(0, 0)];
let cell = buf[Position::new(0, 0)];

let symbol = buf.get_opt((0, 0)).map(|cell| cell.symbol());
let symbol = buf.get_opt(Position::new(0, 0)).map(|cell| cell.symbol());

buf[(0, 0)].set_symbol("🐀");
buf[Position::new(0, 0)].set_symbol("🐀");

buf.get_mut_opt((0, 0)).map(|cell| cell.set_symbol("🐀"));
buf.get_mut_opt(Position::new(0, 0)).map(|cell| cell.set_symbol("🐀"));
```
Replace with indexer (Buffer[])
@joshka
Copy link
Member Author

joshka commented May 21, 2024

TODO rebase once #1084 is merged

Copy link

codecov bot commented May 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.3%. Comparing base (fadc73d) to head (ad40261).

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1123     +/-   ##
=======================================
- Coverage   94.3%   94.3%   -0.1%     
=======================================
  Files         61      61             
  Lines      14768   14823     +55     
=======================================
+ Hits       13935   13982     +47     
- Misses       833     841      +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

Make methods / fields on buffer that deal with the underlying content index private.
1 participant