News for hackers. Stuff that matters.
Re:Rust's 2017 roadmap, six months in by Lerc on Wednesday July 05, 2017 @07:03PM (#14706858)
One of the things that I'd like to see for the Rust Book is some form of "Here's how to use it in a function".

For example, Taking a random piece of code from the Rust Book

    let buffer: &mut [i32];
    let coefficients: [i64; 12];
    let qlp_shift: i16;

    for i in 12..buffer.len() {
        let prediction = coefficients.iter()
                                     .zip(&buffer[i - 12..i])
                                     .map(|(&c, &s)| c * s as i64)
                                     .sum::<i64>() >> qlp_shift;
        let delta = buffer[i];
        buffer[i] = prediction as i32 + delta;
    }

How would one break part of this into a function

    fn get_part ??? What might go here ???  

    let buffer: &mut [i32];
    let coefficients: [i64; 12];
    let qlp_shift: i16;

    for i in 12..buffer.len() {
        let prediction = get_part(&coefficients,&buffer,i)
                                     .map(|(&c, &s)| c * s as i64)
                                     .sum::<i64>() >> qlp_shift;
        let delta = buffer[i];
        buffer[i] = prediction as i32 + delta;
    }

[Exercise for the reader] I'm not sure If I could write the code to do this without taking a few wrong turns.
Re:Rust's 2017 roadmap, six months in by trishume on Wednesday July 05, 2017 @09:39PM (#14707587)
Iterators are the main place this is difficult, but as steveklabnik says the compiler can tell you the return type.

However, this will get better with the introduction of "impl Trait", where the return type will become `impl Iterator<Item = (i64, &[i32])>` which while admittedly long is better than what you'd have otherwise. It's definitely a known pain point.

In practice writing Rust code (full time!) I don't encounter this issue much because I rarely want to split an iterator chain across multiple functions, and iterators are the main place the types get long and hairy. Although I've heard it's really bad with Futures, but that's why "impl Trait" is coming.

Re:Rust's 2017 roadmap, six months in by steveklabnik on Wednesday July 05, 2017 @07:48PM (#14707127)
Well, this code in particular is presented as "hey there's no context." If I were to try to extract this, I would take each of those lets and make them an argument, then see what the compiler says for the return type, done.
Re:Rust's 2017 roadmap, six months in by pjmlp on Thursday July 06, 2017 @12:25AM (#14708124)
This is one example where having a REPL would help a lot.

That is how I check such types outside IDEs in other ML derived languages.

Re:Rust's 2017 roadmap, six months in by roblabla on Thursday July 06, 2017 @06:05AM (#14709227)
TBF, you can just do

    let _ : () = /* some expr whose type you don't know */
And compile it. It will quickly fail with a type error, giving you the full type of the expression.
Re:Rust's 2017 roadmap, six months in by pjmlp on Thursday July 06, 2017 @06:51AM (#14709400)
Yeah, but it feels like a kluge, specially when used to F# on Visual Studio.
Re:Rust's 2017 roadmap, six months in by Lerc on Wednesday July 05, 2017 @10:25PM (#14707740)
How do you find out what the compiler says for the return type? Is that covered in the book somewhere? I feel like this might help me quite a bit in my struggles.
Re:Rust's 2017 roadmap, six months in by bbatha on Wednesday July 05, 2017 @10:31PM (#14707759)
I commonly let the compiler error out by specifying the wrong type or leaving off a type annotation. For instance, https://is.gd/8lLrY8
Re:Rust's 2017 roadmap, six months in by steveklabnik on Wednesday July 05, 2017 @11:15PM (#14707922)
one way is to do

    return SOME_EXRPRESSION;
and then look at the compiler error. Another way is

    let () = SOME_EXPRESSION;
which works as long as SOME_EXPRESSION is not of type (), but if it compiles, well, you know the type :)

Another way is to use some sort of IDE integration that gives you "show me the type on hover".

Re:Rust's 2017 roadmap, six months in by MichaelGG on Wednesday July 05, 2017 @06:58PM (#14706819)
Is seems that Racer is still missing support for auto-complete on basic code snippets:

  let x = vec![1]
  x.<no completion>
Even if they special cased vec! or all the std macros, it'd be a good on-ramp improvement. But I thought RLS was supposed to step in where Racer can't handle things - is that not the case for macro support?
Re:Rust's 2017 roadmap, six months in by saghm on Thursday July 06, 2017 @12:49AM (#14708210)
> Is seems that Racer is still missing support for auto-complete on basic code snippets

Interesting; I view that as a bit more than a "basic" snippet for autocompletion to handle, although that's mostly a few facto interpretation because it's one of the few things that no Rust autocompletion engine I've tried (racer, RLS, or Intellij's plugin) has been able to handle. For pretty much everything else I've tried, at least one of them has been able it.

Re:Rust's 2017 roadmap, six months in by MichaelGG on Thursday July 06, 2017 @05:35PM (#14714157)
Well I mean it's basic in the sense of it's a common piece of code a beginning might write in the first few minutes with Rust.
Re:Rust's 2017 roadmap, six months in by saghm on Thursday July 06, 2017 @05:41PM (#14714184)
Fair enough! I definitely agree with you there
Re:Rust's 2017 roadmap, six months in by steveklabnik on Wednesday July 05, 2017 @07:18PM (#14706964)
You said racer above; did you mean to say the RLS?
Re:Rust's 2017 roadmap, six months in by MichaelGG on Wednesday July 05, 2017 @07:41PM (#14707096)
The linked article mentions that RLS completes via Racer, which is inline with what I understood before: Racer's a lot faster for this use-case, so RLS delegates to it.
Re:Rust's 2017 roadmap, six months in by steveklabnik on Wednesday July 05, 2017 @07:49PM (#14707140)
Yes, my confusion is that in your OP, you were talking a bunch about racer, but then switched to the RLS.

Right now, it's exactly what you said. RLS is still an extremely active project, and so are the compiler internals it relies on, so it's going to gain features in the future. I'm not aware of any specific plans to exclude macros, but it's not my area of specialty.

Re:Rust's 2017 roadmap, six months in by shock on Wednesday July 05, 2017 @04:55PM (#14706014)
I was really hoping we'd have bindings to Qt by now, but looking at the GUI category on crates.io I didn't find any. What do people use to make cross platform GUIs in Rust?
Re:Rust's 2017 roadmap, six months in by nicoburns on Wednesday July 05, 2017 @05:02PM (#14706080)
GTK is the best option at the moment. Apparently QT is difficult due to it being heavily based in C++'s view of the world, which doesn't translate particularly well to Rust (notably Rust not supporting OOP in the same way). There is hope of a new rust-native GUI library (possibly in the vain of Flutter[1]) based on the work done for Servo[2], but that looks to be a way off.

[0] https://www.reddit.com/r/rust/comments/6l5c94/can_we_crowdfu... [1] https://flutter.io/ [2] https://github.com/servo/webrender

Re:Rust's 2017 roadmap, six months in by shmerl on Wednesday July 05, 2017 @05:06PM (#14706108)
I think translation problems aren't caused by OOP itself, but by messed up name mangling, and total lack of any sane standard for it in C++.
Re:Rust's 2017 roadmap, six months in by pcwalton on Wednesday July 05, 2017 @05:22PM (#14706216)
Name mangling is almost completely a non-issue. We solved it years ago for the Servo SpiderMonkey bindings, to name one instance.
Re:Rust's 2017 roadmap, six months in by shmerl on Wednesday July 05, 2017 @05:29PM (#14706276)
What is the most difficult part for Qt then? Translating some of its concepts in Rust?
Re:Rust's 2017 roadmap, six months in by civilitty on Wednesday July 05, 2017 @06:20PM (#14706573)
AFAICT, QT has its own implementation of signals and slots (events and event handlers essentially) which is a pain for Rust's ownership model and it also has a code generator that deals with some of C++'s limitations, making it harder to generate usable bindings. If that weren't enough, there is no native (clean) Rust way to do C++ inheritance which is another big pain.
Re:Rust's 2017 roadmap, six months in by dagmx on Thursday July 06, 2017 @12:01AM (#14708043)
Rust doesn't have a concept of inheritance and overriding which is a pretty key part of the qt design.

If you are okay to use qt out of the box, there are a few bindings. But you won't be able to customise it like you would with actual qt.

Re:Rust's 2017 roadmap, six months in by Rusky on Wednesday July 05, 2017 @05:10PM (#14706130)
Name mangling is by far the easiest part. It's already solved via bindgen and clang.
Re:Rust's 2017 roadmap, six months in by vvanders on Wednesday July 05, 2017 @05:53PM (#14706413)
That only works for clang based static/dyn libs though right? If I remember correctly msvc has a different set of mangling.
Re:Rust's 2017 roadmap, six months in by mwu on Wednesday July 05, 2017 @06:22PM (#14706587)
Clang also supports MSVC mangling. I've never tried it with bindgen, but it can be done.
Re:Rust's 2017 roadmap, six months in by vvanders on Wednesday July 05, 2017 @08:02PM (#14707199)
Huh, nifty. Learn something new every day, thanks!
Re:Rust's 2017 roadmap, six months in by Rusky on Wednesday July 05, 2017 @08:03PM (#14707203)
Clang supports MSVC manglings and bindgen correctly exposes them.
Re:Rust's 2017 roadmap, six months in by dom0 on Wednesday July 05, 2017 @06:06PM (#14706484)
When it comes to UI toolkits, there's just one rule -- "anything but GTK".
Re:Rust's 2017 roadmap, six months in by ronjouch on Wednesday July 05, 2017 @06:17PM (#14706555)
Care to elaborate?
Re:Rust's 2017 roadmap, six months in by flukus on Wednesday July 05, 2017 @08:20PM (#14707268)
I like GTK, but it's place is in gnome (which I also like) and no where else, on any other system it looks horrible and out of place, particularly when it comes to things like the file dialog.

Also the devs no longer consider it a cross platform library, everyone using it as one is stuck on GTK2.

Re:Rust's 2017 roadmap, six months in by the_why_of_y on Thursday July 06, 2017 @06:43PM (#14714560)
GTK is a bazaar style project, if it has issues on some platform then that's because no developers have stepped up to fix issues on that platform.

There's support for Windows native file dialogs since 3.20.

https://blogs.gnome.org/alexl/2015/11/05/native-file-chooser...

Re:Rust's 2017 roadmap, six months in by mkl on Thursday July 06, 2017 @04:21AM (#14708891)
(Not OP) Most gtk applications are very difficult for me to use, for a combination of reasons. I have joint problems that mean I rely on mouse and touch for working with text more than most people. The biggest obstacles are:

1. Gtk constantly clobbers the middle-click clipboard on Linux. In non-gtk programs that's one of my most efficient ways of entering and editing text.

2. Gtk completion dropdowns steal clicks, so typing into a field with completions (that I don't want) with an onscreen keyboard takes at least twice as many button presses as it should.

I have no such problems with Qt (or anything else).

Re:Rust's 2017 roadmap, six months in by dom0 on Thursday July 06, 2017 @07:15AM (#14709504)
Not-Gnome was never a priority for the developers, conversely, it doesn't work very well on Not-Gnome. That alone disqualifies it for me. Besides that, the docs are simply bad and glib is such a huge mess that I actively avoid touching anything near it with a ten foot pole.
Re:Rust's 2017 roadmap, six months in by ronjouch on Thursday July 06, 2017 @09:21AM (#14710163)
@dom0 @flukus of course, thanks. Didn't think of that as I am a satisfied GNOME user (for the continued focus on UX refinement, simplicity, stability) and was even forgetting people might consider it for non-GNOME.
Re:Rust's 2017 roadmap, six months in by wyldfire on Wednesday July 05, 2017 @05:02PM (#14706083)
This thread [1] has some good recent discussion of the current state.

[1] https://users.rust-lang.org/t/current-state-of-gui-developme...

Re:Rust's 2017 roadmap, six months in by shmerl on Wednesday July 05, 2017 @05:01PM (#14706069)
The last time I checked there was this: https://github.com/White-Oak/qml-rust

But it looks stalled. Not sure if anyone is working on such bindings today.

UPDATE: I just found this which looks active: https://github.com/rust-qt/cpp_to_rust

Re:Rust's 2017 roadmap, six months in by kodablah on Wednesday July 05, 2017 @06:18PM (#14706557)
There are some glaring issues w/ the Rust Qt crates, namely subclassing things like QWidget. But it is high priority [0]. This is essential for using Qt as many things are not "signals" but instead overridable protected methods. I started a embedded browser PoC [1] until I hit these limitations which forced me to use C++ [2].

And many other static langs (i.e. not-python) have issues with their Qt bindings (e.g. Go [3] which can't compile via MSVC which some things like the QtWebEngine stuff need). Sadly, for advanced UI (e.g. complex tree views, docking, etc) that is cross platform and looks native, Qt is all there is, and it's reliance on C++ makes it a bit tough to use across languages. A maintained C iface for Qt is really needed.

0 - https://github.com/rust-qt/cpp_to_rust/issues/53

1 - https://github.com/cretz/rust-qt_cef_poc

2 - https://github.com/cretz/qt_cef_poc

3 - https://github.com/therecipe/qt/

Re:Rust's 2017 roadmap, six months in by JoshTriplett on Wednesday July 05, 2017 @05:10PM (#14706125)
bindgen has native C++ support (as of recently), so hopefully that will help.
Re:Rust's 2017 roadmap, six months in by shmerl on Wednesday July 05, 2017 @05:30PM (#14706282)
That's great!
Re:Rust's 2017 roadmap, six months in by rexicus on Wednesday July 05, 2017 @05:34PM (#14706314)
You might try the imgui/nuklear crates, dealing with generated bindings for something massive like Qt will never be pleasant.
Re:Rust's 2017 roadmap, six months in by dom0 on Wednesday July 05, 2017 @06:02PM (#14706458)
Both PyQt and PySide work quite well for something that "will never be pleasant".
Re:Rust's 2017 roadmap, six months in by rexicus on Thursday July 06, 2017 @10:43AM (#14710759)
PyQt and PySide was exactly what I had in mind. It'll leak memory, segfault on load 1% of the time, segfault if you call unrelated methods in the wrong order, you'll randomly get QStrings and QExceptions instead of their Python equivalents, and it'll be impossible to debug.
Re:Rust's 2017 roadmap, six months in by coldtea on Wednesday July 05, 2017 @05:40PM (#14706344)
Nothing much (some OpenGL bindings and such).

They use it for systems software and backend services.

Re:Rust's 2017 roadmap, six months in by clumsysmurf on Wednesday July 05, 2017 @10:18PM (#14707719)
"Even better, you can pre-order a printed version through No Starch Press."

Thanks for choosing a publisher that supplies DRM-free eBooks ;)

Re:Rust's 2017 roadmap, six months in by quodlibetor on Wednesday July 05, 2017 @10:41PM (#14707800)
It's available online: https://doc.rust-lang.org/book/second-edition/ , a publisher that didn't believe in digital sharing that also agreed to publish it would be a little... surprising.
Re:Rust's 2017 roadmap, six months in by clumsysmurf on Wednesday July 05, 2017 @11:07PM (#14707887)
That would be MIT press (sometimes). For example https://mitpress.mit.edu/books/deep-learning is available at http://www.deeplearningbook.org/ , but you can't get DRM-free ePubs or PDFs.
Re:Rust's 2017 roadmap, six months in by steveklabnik on Wednesday July 05, 2017 @11:17PM (#14707930)
You're welcome; this was important to me. In addition, No Starch's commitment to letting the book be generally freely available on doc.rust-lang.org was mandatory, and they are awesome enough to be supportive of that :)
Re:Rust's 2017 roadmap, six months in by artificial on Tuesday July 11, 2017 @11:42PM (#14750005)
Thank you for your efforts. I purchased the book today!
Re:Rust's 2017 roadmap, six months in by ofek on Wednesday July 05, 2017 @05:41PM (#14706350)
Those integrations with other languages look awesome! I just wish there was a good one for Python.
Re:Rust's 2017 roadmap, six months in by Dowwie on Wednesday July 05, 2017 @06:19PM (#14706566)
@mitsuhiko has been working on one: https://github.com/mitsuhiko/snaek

and there's "pythonium trioxide", but I've gotten the impression that its more of an exploratory project: https://github.com/PyO3/PyO3

Re:Rust's 2017 roadmap, six months in by fafhrd91 on Thursday July 06, 2017 @12:54AM (#14708220)
PyO3 is close to first release.
Re:Rust's 2017 roadmap, six months in by Dowwie on Thursday July 06, 2017 @06:04AM (#14709226)
I'm looking forward to it!
Re:Rust's 2017 roadmap, six months in by stusmall on Wednesday July 05, 2017 @06:23PM (#14706600)
Have you seen this one: https://github.com/dgrunwald/rust-cpython

The extension-module feature might give you what you want

Re:Rust's 2017 roadmap, six months in by dbrgn on Thursday July 06, 2017 @05:34AM (#14709125)
This, combined with https://github.com/PyO3/setuptools-rust, is a pretty fantastic way to create native Python extension modules.
Re:Rust's 2017 roadmap, six months in by abiox on Wednesday July 05, 2017 @05:30PM (#14706278)
still hoping that someday we'll see namespacing in crates/cargo.
Re:Rust's 2017 roadmap, six months in by raphlinus on Wednesday July 05, 2017 @06:59PM (#14706827)
This has been discussed quite a bit, and there are very good reasons why not[0]. But I suppose things can always change.

[0]: https://internals.rust-lang.org/t/crates-io-package-policies...

Re:Rust's 2017 roadmap, six months in by Perceptes on Thursday July 06, 2017 @01:17AM (#14708296)
Re:Rust's 2017 roadmap, six months in by aphistic on Thursday July 06, 2017 @02:08PM (#14712470)
I don't think I follow you. Can't you create namespaces using modules?
Re:Rust's 2017 roadmap, six months in by kevinSuttle on Wednesday July 05, 2017 @10:28PM (#14707750)
> We’ve also been working on a number of language changes aimed at improving language ergonomics.

http://bukk.it/clap.gif