ncurses-rs
ncurses-rs copied to clipboard
Make API more natural for Rust
For example, there is no reason to use mutable references for functions like getmaxyx()
: instead of
let mut max_x = 0;
let mut max_y = 0;
getmaxyx(stdscr, &mut max_y, &mut max_x);
you should be able to write
let (max_y, max_x) = getmaxyx(stdscr);
as this is more idiomatic for Rust.
Maybe there are other parts of API which could be modeled better in Rust too, this is the most glaring one.
I understand your concern. ncurses-rs was designed specifically to allow near-one-to-one ports from C code, so it didn't really "rustify" the API at all. Note the first sentence of the README:
This is a very thin wrapper around the ncurses TUI lib.
With that said, providing an orthogonal version with a more rustic API (given the proper refinement and testing, as well as support from the existing ncurses-rs users) might increase the longevity of the project. Alas, I don't have the time for this now; we need a new hero to take the reigns.
I say leave the library as plain and simple wrapper, and handle high-level stuff in a separate library.
This issue isn't that the library should be more abstract, but that the constructs aren't idiomatic for Rust.
@marcusklaas yes good point. This library wouldn't have to be abstract to be rust idiomatic.
@jeaye I'd argue that one-to-one ports from C into Rust would barely take advantage of the new language, since a main selling point of Rust is that you don't have to use mutability everywhere to write memory-efficient programs. I propose that ncurses is wrapped the other way around: The C-compatible API should be built on top of the idiomatic one.
With that said, providing an orthogonal version with a more rustic API (given the proper refinement and testing, as well as support from the existing ncurses-rs users) might increase the longevity of the project. Alas, I don't have the time for this now; we need a new hero to take the reigns.
@untitaker ^
For a more Rustic API, you can probably use pancurses which aims "to provide a more Rustic interface over the usual curses functions for ease of use while remaining close enough to curses to make porting easy." It's a wrapper for this (on Unix) and pdcurses-sys (on Windows).