> Unlike nearly every language I’ve ever used, Rust actually encourages variable shadowing. Haskell does it too, for the same reason/purpose / with the same effect.
Swift does, but typically for Optional promotion. You see stuff like `guard let delegate = delegate else { return }` inside functions all the time, shadowing a property with a local & promoting the type from Optional to T. It's not the same as the Rust example because you're shadowing an ivar to a local, but since `self.` is implicit you're still shadowing.
Thoughts on Rust, a few thousand lines in
51–60 of 183 posts
Re: Thoughts on Rust, a few thousand lines in
#52> the escape hatch suggested on the internet, `partial_cmp(...).unwrap_or(Ordering::Less)` This is often a Bad Idea, as you get unstable sorts and you are right back to the same problem. - Explanation: How do I get the minimum or maximum value of an iterator containing floating point numbers? — https://stackoverflow.com/a/50308360/155423 - Example: https://play.integer32.com/?version=stable&mode=debug&editio... See a…
Re: Thoughts on Rust, a few thousand lines in
#53Earlier quoted context omitted.
Why not this? fn main() { let a = "ab早".as_bytes(); let a = &a[..3]; println!("Hello, world!"); }
It's not clear to me what you're suggesting; is it that String shouldn't have supported indexing in the first place? That code does work, but you have a &[u8] not a &str.
Re: Thoughts on Rust, a few thousand lines in
#54One thing I don't like about Rust is how taking a slice of a string can cause a runtime panic if the start or end of the slice ends up intersecting a multi-byte UTF-8 char. I would prefer it if this feature didn't exist at all rather than cause runtime panics. https://play.rust-lang.org/?gist=e02ce5e9aacfee3a2b4917d5624...
Re: Thoughts on Rust, a few thousand lines in
#55> Like Go, Rust can compile statically linked linux binaries. The GNU C library (needed not only by C programs for C things) doesn't support static linking, so the only way this is possible is to use another library entirely, or raw inlined syscalls (where applicable).
Yes, we have full support for MUSL. It's a $ rustup target add x86_64-unknown-linux-musl $ cargo build --target x86_64-unknown-linux-musl away.
(And if you need to link against common C libraries like OpenSSL or PostgreSQL, I maintain a Docker image with the necessary C toolchains, and instructions on how to use it: https://github.com/emk/rust-musl-builder. There are a couple of similar images out there, too, I think.)
Re: Thoughts on Rust, a few thousand lines in
#56Earlier quoted context omitted.
Why not this? fn main() { let a = "ab早".as_bytes(); let a = &a[..3]; println!("Hello, world!"); }
It's not clear to me what you're suggesting; is it that String shouldn't have supported indexing in the first place? That code does work, but you have a &[u8] not a &str.
Re: Thoughts on Rust, a few thousand lines in
#57Rust is one of the few times where the language/ecosystem does precisely what I wished it would do. For instance, being able to partially destructure JSON into a struct in a typesafe manner is just awesome.
This sounds really useful, you don't happen to have an example of this do you? Thanks in advance!
https://github.com/rcoh/angle-grinder/blob/master/tests/stru...
Re: Thoughts on Rust, a few thousand lines in
#58Earlier quoted context omitted.
But how do you know just by reading that code? It would not be obvious to me at all.
You mean if you don't know the language?
Re: Thoughts on Rust, a few thousand lines in
#59Earlier quoted context omitted.
But how do you know just by reading that code? It would not be obvious to me at all.
let foo = bar; let foo = bat; is shadowing let foo = bar; foo = bat; is a compilation-time error because foo isn't mutable. let mut foo = bar; foo = bat; is reassignment. in working code, either foo is declared as mutable or it's not, and it's pretty obvious from the code what's happening.
Re: Thoughts on Rust, a few thousand lines in
#60This makes me want to add `p90`, `p50` and so on to jq...