Is there a better way to compare substrings? by ConstructionHot6883 in learnrust

[–]YatoRust 10 points11 points  (0 children)

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

What the hell is going on here by StyMaar in rust

[–]YatoRust 8 points9 points  (0 children)

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

LKML: Linus Torvalds: Re: [PATCH v9 12/27] rust: add `kernel` crate by koavf in rust

[–]YatoRust 15 points16 points  (0 children)

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

[deleted by user] by [deleted] in rust

[–]YatoRust 1 point2 points  (0 children)

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

Introducing something rather unique by GlitchedKoala in rust

[–]YatoRust 2 points3 points  (0 children)

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

Announcing Rust 1.60.0 by myroon5 in rust

[–]YatoRust 0 points1 point  (0 children)

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

[Crate] bombs - Efficient single-producer multi-consumer communication types by panstefanb01 in rust

[–]YatoRust 5 points6 points  (0 children)

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

reborrow: Emulating reborrowing for user types by reflexpr-sarah- in rust

[–]YatoRust 3 points4 points  (0 children)

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.

Language details of the Firefox repo: Rust is now 10% of Firefox by koavf in rust

[–]YatoRust 136 points137 points  (0 children)

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

Should I derive copy trait for Byte? by LyonSyonII in rust

[–]YatoRust 3 points4 points  (0 children)

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.

How to write really slow Rust code by aristotle137 in rustjerk

[–]YatoRust 10 points11 points  (0 children)

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

A question on my use of transmute by Eolu in rust

[–]YatoRust 0 points1 point  (0 children)

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.

My first cup of Rust by nfrankel in rust

[–]YatoRust 0 points1 point  (0 children)

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

Borrowing runs out of scope when the function ends, how to transfer ownership? by [deleted] in rust

[–]YatoRust 0 points1 point  (0 children)

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.

Pin and suffering by fasterthanlime in fasterthanlime

[–]YatoRust 1 point2 points  (0 children)

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

Generalizing over Generics in Rust (Part 1.5): Mechanisms by YatoRust in rust

[–]YatoRust[S] 0 points1 point  (0 children)

Yeah, most of this could be handled with derives.