jeaye / ncurses-rs

A low-level ncurses wrapper for Rust
Other
677 stars 101 forks source link

Make API more natural for Rust #46

Open netvl opened 9 years ago

netvl commented 9 years ago

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.

jeaye commented 9 years ago

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.

osa1 commented 9 years ago

I say leave the library as plain and simple wrapper, and handle high-level stuff in a separate library.

marcusklaas commented 9 years ago

This issue isn't that the library should be more abstract, but that the constructs aren't idiomatic for Rust.

alexispurslane commented 9 years ago

@marcusklaas yes good point. This library wouldn't have to be abstract to be rust idiomatic.

untitaker commented 9 years ago

@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.

jeaye commented 9 years ago

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 ^

gbear605 commented 6 years ago

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).