8 ms·
Rust 1.43
- steveklabnik 7y agoHey folks, this is the first release after I wrote https://words.steveklabnik.com/how-often-does-rust-change https://words.steveklabnik.com/how-often-does-rust-change. We haven't changed any real policy here, but the bit saying > This release is fairly minor. There are no new major features. We have some new stabilized APIs, some compiler performance improvements, and a small macro-related feature. See the detailed release notes to learn about other changes not covered by this post. is an attempt by me to maybe address this. We've historically said similar-ish things, but I'm trying to be a bit more blunt about the magnitude of changes. Any feedback on this would be useful!
- deleted 7y ago[deleted]
- deleted 7y ago[deleted]
- greatgirl 7y agoThank you. I wonder how long this will hold though? I would not like to see it get to a point where the language is fine but people aren't really sure what else to do and just make changes for the hell of it. In other words I think there needs to be a long term standardisation plan to keep the language stable, but for now this is a good step.
- steveklabnik 7y ago> I would not like to see it get to a point where the language is fine but people aren't really sure what else to do and just make changes for the hell of it. We never make changes for the hell of it. But also, all changes are purely additive at this point. The language is stable. It has been for years.
- greatgirl 7y agoIn that case I think keeping up very small additive changes is good, thanks for clearing up
- estebank 7y agoTo expand on Steve's point, code written in 1.0 style should continue to work indefinitely, modulo soundness fixes, lints and plain old bugs. You should only need to update at your own pace or because your dependencies force you to, and they shouldn't do so often if they care about supporting as many users as possible. Big changes, like async/await sugar or impl Trait or the ? operator are uncommon and they either make your code that much nicer to read or allow new constructs that were previously impossible.
- andrewflnr 7y agoI think the key thing people worry about with regard to "churn" is "OMG, do I have to update my code again?". Explicitly calling out that this release doesn't really have any changes like that is good. I also think that's why the ecosystem change is in fact a big deal. People seem to feel pressured to keep up. Meanwhile I'm still not really sure what the consensus is, if any, on which error handling library we're supposed to use... Anyway, it might also be worth calling out somewhere that no, you don't have to follow the ecosystem and the hip idioms super closely if you just want to get some work done (and to the extent that's not true, making it so).
- steveklabnik 7y agoThanks :) The current error handling consensus seems to be "anyhow for applications, either no crate or thiserror for libraries." Obviously this is not uniform, but the discussion + download counts point to this, imho.
- ucarion 7y agoTo clarify for others: "anyhow" and "thiserror" are not placeholder names in that sentence. They refer to: https://github.com/dtolnay/anyhow https://github.com/dtolnay/anyhow https://github.com/dtolnay/thiserror https://github.com/dtolnay/thiserror
- ChrisSD 7y agoJust to be clear, you never HAVE to update your code. Rust 1.0 code still works just fine. The consensus with error handling is that the limitations of std error trait have now been sufficiently fixed so as to be usable without anything more. But you can use a crate (like `thiserror`) to reduce boilerplate if you really want to.
- est31 7y ago> Just to be clear, you never HAVE to update your code. Rust 1.0 code still works just fine. You have to update your dependencies though because every now and then, changes lead to breaking builds. I have a codebase from 2015, last touched in 2016, and many dependencies failed to compile, some because of changes in the language (those changes are only done to fix bugs but they still cause churn to users), others because the openssl wrapper doesn't support newer natively installed versions of openssl. It took me roughly an hour to fix all the issues and it's only a few hundred lines. Admittedly this is much much less effort than staying up with whatever the currently hyped error handling library is. And C++ projects often need effort to work on newer compilers as well because they invoke UB and the optimizer changed and led to segfaults. Seen it with my own eyes.
- harikb 7y agoFor a non-rust person's point of view, I assume a macro is something like a super-pre-processor that helps keep the code concise. In the example below, what portion is written ahead of time (by the person making the macro) and what portion is the macro usage? macro_rules! mac_trait { ($i:item) => { trait T { $i } } } mac_trait! { fn foo() {} } Is this making it easier to implement a trait? interface?
- progval 7y agoThe first block defines a macro; the second block is the macro usage. The goal of macros is to deduplicate code; either inside a function or to implement traits (eg. the Debug trait, that allows printing a structure/enumeration/... recursively; this would be very boring to implement yourself every time)
- zamalek 7y agoThe first block (macro_rules!) the declaration is written by the macro author, the second block (mac_trait!) is the usage written by the user. Note that macro_rules is itself a macro. `trait T {}` and `fn foo() {}` are used in the final code, which would be: trait T { fn foo(){} }
- harikb 7y agoThanks. I am trying to understand where the savings for the user is (as in less code to type). I guess it is somehow related to T being a generic and if they didn't use this macro, they would have had to repeat this all over?
- aliceryhl 7y agoOne common usage is to use macros to repeat some definition for every integer type. In this case T is not a generic, but the name of the trait.
- estebank 7y agoIn the example given the macro is almost useless. The benefit comes if you want the expanded code to have more things, like methods defined that otherwise you would have your consumer write or sister methods and types. The macros are only about convenience on usage and reduction of boilerplate. A good example is the vec![1,2] macro call that expands to { let mut x = Vec::new(); x.push(1); x.push(2); x } The reason the blog post is using that example is because it's showing a new type of macro argument which accepts items (functions, structs, enums, traits and impls) and expands them correctly without any extra needs by the macro writer.
- axegon_ 7y agoMinor or not, this: > You can now use associated constants on floats and integers directly, rather than having to import the module. That is, you can now write u32::MAX or f32::NAN with no use std::u32; or use std::f32;. is neat! Awesome! Thanks!
- kibwen 7y agoThat's my RFC! Yes, it's great to be able to address such a curious (albeit minor) historical wart from Rust 1.0. :) https://github.com/rust-lang/rfcs/blob/master/text/2700-associated-constants-on-ints.md https://github.com/rust-lang/rfcs/blob/master/text/2700-asso...
- digikata 7y agoThe added cargo env variable pointing to the path of generated binaries is a nice quality of life fix. I think that was one of the first annoyances I ran into with cargo and binaries. It was minor but was like a little splinter that stood out from cargo's otherwise nicely integrated build and test capabilities.
- jeffdavis 7y agoI'm curious why there's no similar variable pointing to a built library (e.g. a cdylib).
- steveklabnik 7y agoWhat's the use case?
- jeffdavis 7y agoI feel like I've been pushing my use case plenty already, so please take this as an answer to your question rather than one more push ;-) I'd like to be able to create plugin-style cdylibs that get loaded into a host program. For instance, PostgreSQL extensions are shared libraries (typically written in C) that need to be loaded into a running instance of postgres for integration testing. I am trying to make it reasonable to write such extensions in rust (https://github.com/jeff-davis/postgres-extension.rs https://github.com/jeff-davis/postgres-extension.rs). The environment variable to find the shared library would solve one problem, but there are still a couple more right behind it: * Running "cargo test" tries to build a binary that links to the library to run the unit tests, but this will fail because there are unresolved symbols in the .so file (symbols that call APIs in the host program, in this case PostgreSQL functions like palloc()). In other words, the test binary is useless because it can't load the plugin. * Linux seems fine creating a .so with unresolved symbols, but Mac and Windows need special linker flags. I can document that the linker flags are needed by consumers of my crate, but it would be nice if there was a better/supported way to create plugin-style shared libraries. I tried filing a bug with PR (https://github.com/rust-lang/rust/pull/66204 https://github.com/rust-lang/rust/pull/66204) it was determined that it needed to go through the RFC process. The simplest way to see the problem is to look at this crate: https://github.com/jeff-davis/unresolved https://github.com/jeff-davis/unresolved My problems don't end there, unfortunately. For my crate to really work, I also need to solve the problem of setjmp/longjmp at the edges between C and Rust (https://github.com/rust-lang/rfcs/issues/2625 https://github.com/rust-lang/rfcs/issues/2625).
- nevi-me 7y agoThe primitive type inference is helpful, especially given the number of `val as i32` conversions that one might encounter when doing arithmetic from different crates. It however feels "magical", so I'm not sure of how I feel about it. Do the primitive type inferences also work when comparing i32 vs &i32, or even better, &i32 vs &u64?
- steveklabnik 7y agoYes, all combos of &T and T on both sides of the operator do. Sorry for not being more explicit about that in the post!
- simias 7y agoI believe that this only works for literal type inference, i.e.: let a: f32 = 0.0; let b: f64 = 0.0; let this_works: f32 = &0.0 + 0.0; let this_doesnt: f32 = &a + b; And that's a good thing IMO, implicit promotion rules in C are one of my least favourite features of the language. It makes it so easy to write seemingly innocuous code that's completely broken.
- steveklabnik 7y agoYes, it is only for literals.
- djrenren 7y agoThis seems like an odd choice... do you know the rationale? (or have a link to an issue/RFC I could go read)
- steveklabnik 7y agoI am finding it a bit tough to explain concisely, maybe go check out https://github.com/rust-lang/rust/pull/68129/ https://github.com/rust-lang/rust/pull/68129/ and it might help?
- majewsky 7y ago
- giancarlostoro 7y agoI always check these announcements out wondering when Rocket will compile on stable. https://github.com/SergioBenitez/Rocket/issues/19 https://github.com/SergioBenitez/Rocket/issues/19 Anyone have any background on what's holding back proc_macro_hygiene and why that's even a requirement of Rocket?
- steveklabnik 7y agohttps://news.ycombinator.com/item?id=22609943 https://news.ycombinator.com/item?id=22609943
- giancarlostoro 7y agoVery insightful thank you, is it not possible for Rocket to rewrite some of those if it's going to take a while before they're ready for Rust? Another thought I had is... does Rust support conditional compilation? I haven't done enough Rust to know but maybe they could do that for Stable instead...
- steveklabnik 7y agoWe do, and that’s part of what I meant in the comment by “dropped”; the first one can’t be worked around, but the others could, in theory. That said I’m not an expert on Rocket and don’t know what Sergio’s plan is exactly.
- giancarlostoro 7y agoFair enough, out of curiosity are there other frameworks you have used or find interesting?
- steveklabnik 7y agoIf I were to make a service today, I would probably start with Actix, or maybe Warp. I don't think that this problem has really been solved yet. I've taken a few cracks at it myself over the years and am still not 100% happy, I dunno. The last time I wrote something I just used raw hyper. I didn't need complex routing though, if I did, that would have been an absolute pain. It was also a read-only service so I didn't need auth or a lot of other stuff that's needed in every real app.
- Analemma_ 7y agoI wonder if recency bias combined with the unusually large volume of major changes in 2018 was responsible for Preston Carpenter's "I can't keep up with Rust" post (https://news.ycombinator.com/item?id=22818150 https://news.ycombinator.com/item?id=22818150)
- greatgirl 7y agoI would say there is an argument to be made on both sides. On one hand rust is only 10 years old with much less corporate backing than Go, but on the other hand you have to be very careful with even small changes if you want the language to be stable in the long run. I can see why people are worried, and it's valid, but I also trust the devs are making correct choices
- steveklabnik 7y ago> On one hand rust is only 10 years old Periodization is hard; it's been five years since Rust 1.0. The project is much older, but the language as we know it today has only been around half that time.
- majewsky 7y ago> rust [has] much less corporate backing than Go I don't know if that statement is really justified. Sure, Google is a much bigger and more influential company than Mozilla. But when taking the average over the entire company, all-of-Google supports Go much less strongly than all-of-Mozilla supports Rust, and I think that pretty much cancels each other out the company size, so I would consider both langs to have roughly equal corporate backing. I think the actual difference is that Go has a much larger immediate audience than Rust. Go appeals primarily to developers of web service backends, who are coming from Ruby/Python/Perl/PHP and are looking for something faster and statically typed. Rust OTOH initially mostly appealed to systems developers looking for a better C/C++, although that audience has been steadily expanding since then.
- steveklabnik 7y agoRust is also supported by more than Mozilla these days.
- valera_rozuvan 7y agoIf you are like me, and stick to Rust lang for about a year or so, you will have a hard time going back to low level languages such as C. When you have your errors caught at compile time - it's simply beautiful! Forget about explicit memory freeing - and don't worry about memory management, it is really predictable. Code will always have the same precise meaning across all platforms. Hell yeah!
- tiles 7y agoOn the bright side, I definitely write safer C code now after wrapping my head around Rust. I'd much rather have the compiler tracking lifetimes than my own imagination though.
- anarchyrucks 7y agoI finally "understood" C++ after writing a bit of Rust and studying the ownership principle.
- qchris 7y agoIt took me a little while to get my system down, but once I'd figured out how to build and call in Rust libraries using CMake and the the C ABI, I do my best to write as little raw C++ as I can. Using the Rust test framework, limiting direct memory management to the low number of unsafe functions I need to pass raw data/pointers across that FFI boundary, being able to count on the compiler to check if I'm doing something dumb, and being able to easily add other dependencies into that Rust .so/.a file product Cargo have all been huge productivity boosts compared to pulling out valgrind/gdb whenever I run into a segfault because I've done something stupid.
- coldpie 7y agoAfter years of watching Rust excited, I finally have an opportunity to use it this year, and I'm loving it. Like you say, going back to C feels weird and cumbersome (ugh I have to free this in _how_ many places?).
- ccktlmazeltov 7y agosame here, I will never write C or C++ again
- otikik 7y agoAll those new features sound so ... unexciting. I like that!
- kettro 7y agoThe one feature I need on stable is inline assembly. It's something that should not be sidelined to the nightly compiler, and makes Rust a harder sell for the embedded world. Yes, I know that I can just use .S files for my assembly, but sometimes I just need to access a CSR.
- steveklabnik 7y agoIt’s closer than it’s ever been! There’s been a lot of renewed interest, with an RFC and an implementation. We’ll see!
- philonoist 7y agoConsidering all the excitement here, I want to learn Rust. What is a good resource to start with if I didn't program ever?
- pdimitar 7y agoThe official book is fairly beginner friendly but some background of computer knowledge is unskippable if you want to progress with programming. https://doc.rust-lang.org/stable/book/title-page.html https://doc.rust-lang.org/stable/book/title-page.html