Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
Measter
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
21 ms
·
181.
▲
by
Measter
6y ago
What exactly is the difference here? Is the `x` variable being updated in the second sample so that the stored references all point to the same item?
182.
▲
by
Measter
6y ago
Meanwhile, in the much more complicated Rust, all but four of those are one-liners[0]. The exceptions being: * Expand. Rust doesn't provide an easy way to insert multiple values into the middle of a vector, so I had to do 2 lines: appe
183.
▲
by
Measter
6y ago
While not a dependently-typed language, the Rust compiler can do this here for arrays. Arrays in Rust have the length as part of their type, which is compile-time constant, and if you're indexing with another compile-time constant the
184.
▲
by
Measter
6y ago
Popping doesn't touch the allocator, as it doesn't resize the backing storage. The only thing being copied is the String struct (24 bytes), which while unnecessarily large here, wouldn't be the bottleneck.
185.
▲
by
Measter
6y ago
> Are there static type systems that make it easy to work with types like that? In Rust things that can be rendered to a string (in a user-friendly manner) implement the Display trait. A slice of things that can be rendered would have th
186.
▲
by
Measter
6y ago
In Windows Terminal you can just hold CTRL and scroll, or the default key bindings are CTRL+= and CTRL+-.
187.
▲
by
Measter
6y ago
Rust is a bit notorious for its string-related complexity, and that's for the reasons you talked about. The most common form of string you'll see is `String`[0], or its view type `str`[1], which are UTF-8 encoded. These have most
188.
▲
by
Measter
6y ago
There's nothing stopping you from doing a functional style in Rust, neither: https://play.rust-lang.org/?version=stable&mode=debug&editio... There is a function on nightly that would make line 16 a little nicer
189.
▲
by
Measter
6y ago
That `Integer` type can't implement `Copy` because it manages a resource, meaning you can't just do a simple memcpy of the type.
190.
▲
by
Measter
6y ago
Yes, that's the trivial "fix" to make it work, but that's not my point. In most other similar situations the compiler does that for me, but not here. It feels like something the compiler should be doing, not me.
191.
▲
by
Measter
6y ago
Unfortunately that is not always the case. This fails to compile, for example (and is fairly irritating): let my_str = "Hello".to_owned(); match &my_str { "Hello" => (), _ => () }
192.
▲
by
Measter
6y ago
There was a survey posted on the subreddit[0], which asked about which language people used. I was quite surprised to learn that Rust was the second-most used at 10% (45% used Python). [0] https://www.reddit.com/r/adven
193.
▲
by
Measter
6y ago
This is what I ended up with: fn search<T: Ord>(haystack: &[T], needle: &T) -> Result<usize, usize> { let mut range = 0..haystack.len(); while !range.is_empty() { if range.len() == 1
194.
▲
by
Measter
6y ago
But that backtrace doesn't actually tell you what function the error occurred in. The function stack would be this (discarding everything outside of my code): 1: ImageData::verify_and_update - src\main.rs:104 2: run - src\mai
195.
▲
by
Measter
6y ago
The mindset is that an program output like this in the event of a user input error is not good: Cup 60 skins in DB 104 drivers in DB thread 'main' panicked at 'Could not find car folder or its skins: acrl_po
196.
▲
by
Measter
6y ago
Ah, so you did. My apologies, I misread.
197.
▲
by
Measter
6y ago
Why would copy-pasting force retention of ligatures? Ligatures don't change the underlying characters, only the graphical representation of them.
198.
▲
by
Measter
6y ago
Of course. A `==` is two characters long, while `===` is three characters long. Also, with the font I use (Fire Code) the `===` ligature has three lines, making it even easier to distinguish.
199.
▲
by
Measter
6y ago
I develop on Windows, and my experience has been that unless a crate is specifically written for another platform, they generally work perfectly fine on Windows with two exceptions: 1. Terminal-related functions. This is getting better as c
200.
▲
by
Measter
6y ago
Huh... that's actually faster than I expected. I figured that the normalization processing overhead would be higher than that.
201.
▲
by
Measter
6y ago
Would you be willing to test my implementation[0] also? It'd be interesting to see the overhead of the (overkill) string normalization I do, along with the much reduced pressure on the allocator compared to yours. [0] https:/
202.
▲
by
Measter
6y ago
You're welcome. The implementation in the OP uses a more functional style, but that's not the only way Rust is commonly written. I also did an implementation[0] (because I have nothing better to do) using more of an imperative sty
203.
▲
by
Measter
6y ago
So, this[0] is the doc page for the `GlobWalker` type. One of the traits it implements, and the only one relevant here, is the `Iterator` trait from the standard library[1]. That's how you'd know that the `filter_map` function is
204.
▲
by
Measter
6y ago
On Windows Rust calls out to `CreateFileW`[0], and by default uses the `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE` share permission[1]. [0] https://github.com/rust-lang/rust/blob/master/libra
205.
▲
by
Measter
6y ago
In one sense, the way that larger crates in Rust are fragmented does address some of that. This does result in large dependency trees, but it does also mean that if you need that one specific functionality, you may not need to pull in the f
206.
▲
by
Measter
6y ago
> C++ you literally take strings and overwrite characters, where now people duplicate lists of records just to stay clean. When you're dealing with UTF-8, you can't overwrite your buffer in the general case because changing cas
207.
▲
by
Measter
6y ago
In Rust: "a, b".split(", ")
208.
▲
by
Measter
6y ago
One thing to bear in mind is that the libc and winapi crates are bindings to the libc and Windows C headers, so every single function signature in there will be marked unsafe because it's FFI, so those will be heavily impacting your re
209.
▲
by
Measter
6y ago
And probably even less aware of the other 11 million people murdered by the Nazis in their camps.
210.
▲
by
Measter
6y ago
Author here. I would definitely second these two links. They were very helpful in getting started, and later when I wanted to declare an interrupt handler.
More ›