u/YatoRust

441 post karma · 1,869 comment karma · joined Jan 2019

YatoRust

Oh man :(

YatoRust
YatoRust

you could use string.starts_with("your prefix") to check the prefix without worrying about length errors.

On the note of performance, always measure first to see if it's actually a problem. If it is, then you could consider using logos to parse out the prefix. logos compiles down to a DFA, and will only look at each byte once.

logos: https://lib.rs/crates/logos

YatoRust

Changing debug representation is fine. You're not supposed to rely in it.

YatoRust

Sorry i meant Miri

YatoRust

Probably related to the RustBelt project and work done on MIRI.

YatoRust

This one works a lot better and has more colors, I think it's like semantic colors for asm.

YatoRust
YatoRust

This particular implementation is unsound because of loops :). You can store previous iterations and use those tokens to access the values exclusively twice

YatoRust

But usually not if there's a branch/allocation in the way

YatoRust

Np, unsafe is hard and this was a subtle bug :). In the future, look out for this when you use ptr::read.

YatoRust
YatoRust

If you change the trait definitions to something like

trait Reborrow<'a, _Outlives = &'a Self> {...}

It lets you use the trait bound T: for<'a> Reborrow<'a> for example.

YatoRust

I would reccomend using this pattern so that Reborrow[Mut] works well with HRTB

https://users.rust-lang.org/t/lifetime-conflicting-requirements/64070/4

YatoRust

It's not. Its 27% Javascript. They have too similar colors. Asm is a tiny sliver at the top of the circle

YatoRust

That doesn't compile :)

YatoRust

NOTE move and copy lower to the exact same memcpy, the only difference between them is if you are allowed to access the value after you move/copy it. So there isn't really a perf angle to this, unless you have a very large type (in the order of kilobytes) and you want to prevent accidental copies. But then, even moves can be relatively expensive in a hot loop.

YatoRust

Here's a modified version that doesn't require patterns, can take an arbitrary path, and doesn't allow typos.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=aad5af1a7bb8cdccfe8b9f4c53533628

YatoRust

Every line, are you trying to be fast! We must lock on every character, that is the way.

YatoRust

No, that transmute isn't valid. It's better to keep implementation details hidden until it becomes necessary to expose them. Transmuting repr(Rust) types is unspecified behavior, and will almost certainly run into undefined behaviour for non-trivial types like VecDeque. Unless the type has a well specified layout, you can't use transmute.

YatoRust

This copies a reference which isn't the same as returning a reference to the iterated item. Try converting to array::IntoIter::new(v) instead of v.iter() and you will see errors

YatoRust

It means this student is cheating, even though they said not they wouldn't. Usually schools have a academic honesty "contract" that students need to sign and follow. It usually says they can't ask for answers online (among other things). If they need help they need to go to resources at school such as professors or teaching assistants. But they should have all the knowledge to put this together.

YatoRust

That's a typo, it should be Pin<Box<_>> in the code,

YatoRust

Wtf

YatoRust

Yeah, most of this could be handled with derives.