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
Add methods that return results / options for fallible operations #1011
Comments
The currently allowed lint clippy::missing_panics_doc catches a bunch of these cases and requires to write a panic documentation. Then we just need to seek documentation including this panic section. Also, other lints detect arithmetic or array access out of bounds that can panic. A lot of this should be detectable by enforcing more lints. |
Good idea - added to the solution. |
See #1047 which does something similar despite |
I was thinking about how to best migrate some of the methods that have poor adherence to the general rust API standards like this. An alternate approach is to fix the methods properly (i.e. the #[cfg(not(feature = "legacy-buffer-methods"))]
fn get<T: Into<Position>>(position: T) -> Option<&Cell> {
...
}
/// This is included to make it easy to upgrade, blah blah blah feature flag,
#[cfg(feature = "legacy-buffer-methods")]
#[deprecated]
fn get(x: u16, y: u16) -> &Cell {
...
} This would allow us to release the new feature in a (mostly) non-breaking manner, but then change the default feature flags in a future release. We might also consider implementing the Index trait (though I'm not sure whether this should be indexed using |
This forces someone to migrate everything at once. Also, I am not sure what happens with dependencies. My widget is in a different crate, it enables a feature. What about the one using that widget. Is that feature needed then too? |
Also, rust best practices guidelines have this to say:
https://rust-lang.github.io/api-guidelines/naming.html#getter-names-follow-rust-convention-c-getter |
I vaguely recall writing a response along the lines of "ah yes, you're right of course, feature flags are a problem when there are multiple paths to the crate that could have different feature flags". Either it was on a different issue with a similar idea or I might have not posted it. Either way, yeah you're right that's not a viable approach. |
@EdJoPaTo do you have any thoughts about making whether to make this a breaking change compared to using For context the impact of this external to ratatui is ~118 files: |
Probably results in a lot of internal churn. Earlier when looking at git blame for the |
Was curious why my usage of it doesnt show up: I dont name them buf, I name them buffer. Interestingly, they still dont show up. Query used: |
At least one result in ratatui "buffer.get" AND (NOT org:ratatui-org) AND (NOT is:fork) |
Ah… my |
Problem
There are a variety of places, usually in calls to Buffer, where things can fail.
These methods should generally have alternatives that fail with an Err result, or return None instead of panicking.
Solution
try_xxx() -> Result
Alternatives
Additional context
Specifically Buffer::get() is a place that often causes panics.
The text was updated successfully, but these errors were encountered: