An Optimization That Is Impossible In Rust
Unlock all features
FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.
Unlock all features
FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.
Unlock all features
FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.
Unlock all features
FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.
Unlock all features
FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.
Related videos
THIS IS IMPOSSIBLE
Timcast
64.7k views
Linus x Linus - Is AI A Bubble?
ThePrimeTime
37.4k views
LLMs are in trouble
ThePrimeTime
611.4k views
What even is an AI Agent?! (The Standup)
ThePrimeTime
91.9k views
Why is the Rust Compiler So SLOW?
ThePrimeTime
98.2k views
The AI Girlfriend situation is SAD
ThePrimeTime
121.3k views
Zig and Rust in Production (ft. Matklad)
ThePrimeTime
93.2k views
Linux Dev on Rust, OSS and Rewriting SQLite
ThePrimeTime
83.9k views
Devin Is A Lie?
ThePrimeTime
240.2k views
It's Really Just That Bad
ThePrimeTime
380.2k views
Top Comments (10)
There are at least two Rust libraries with this exact optimization, for strings and vectors respectively. Also Rust lets you embed assembly directly in the code, in case you need one of the few niche things not supported by unsafe blocks. Some things may not lead to "clean" code but anyone who says something isn't possible in Rust probably never checked.
Primogen: I do not comment on politics Also Primogen: German strings!
Hey Prime. A PhantomData is simply a type marker for the compiler. Let's say we have a trait that has functions that work with a certain generic type D. We want to apply that trait to a new Struct we created. But that struct doesn't have the type D. Like this: pub struct Something<D: SomeTraitYouNeed>{ ... } The struct has the generic marker D, but it doesn't have any of its attributes that follow the requirements of D. This will confuse the compiler because it will not be sure of how to apply the trait rules. In that case we create a PhantomData that implements those rules: pub struct Something<D: SomeTraitYouNeed> { PhantomData<D>, .... } PhantomData is just to fulfill the rules of the compiler, it will not exist in the compiled source code. Edit: Here is an example of a use for this. I once created a Worker struct for running custom functions in multi-threaded environments. It requires a trait for the parameter of the function, and another for the function it is going to run. It stores the parameters of the function, so that is okay. It doesn't store any attribute that implement the trait of the function it is going to execute. Due to that, I needed to implement a PhantomData for the function it is going to execute. Edit: For those unfamiliar with Rust. Traits are interfaces. Or, in simpler terms, a "class" with only functions. A generic is a "type that implement ("inherit") a certain trait ("Interface").
27:46 that's why its german, ITS OVERENGINEERED
The whole article is just kind of wrestling with the semantics of the language lol
In this case PhantomData is there mostly because of variance, the struct is now covariant to T because it is naturally covariant to PhantomData<T>. To explain variance: There exist three types if variance. Covariant<T>: 'a if T: 'a // a restriction in T leads to a restriction in Covariant<T> Invariant<T> if T: 'a // a restriction in T does nothing to Invariant<T> 'a: Contravariant<T> if T: 'a // a restriction in T loosens restrictions in Contravariant<T> Examples on how to make those types: struct Covariant<T>(T); struct Invariant<T>(*T); struct Contravariant<T>(fn()->T);
Reminds me of strings is Pascal
What? Polars the python library is written Rust. They are not two separate things.
I really like those type of videos.
gotta optimize that Rust weapon handling
Unlock the Data Inside
Turn Videos into Knowledge
- Get FREE 10/day: transcripts, summaries, chats
- Chat with videos, export text & PDF
- $1 free API credit for RAG, chatbots & research
Free forever plan • All features unlocked
Top Comments (10)
There are at least two Rust libraries with this exact optimization, for strings and vectors respectively. Also Rust lets you embed assembly directly in the code, in case you need one of the few niche things not supported by unsafe blocks. Some things may not lead to "clean" code but anyone who says something isn't possible in Rust probably never checked.
Primogen: I do not comment on politics Also Primogen: German strings!
Hey Prime. A PhantomData is simply a type marker for the compiler. Let's say we have a trait that has functions that work with a certain generic type D. We want to apply that trait to a new Struct we created. But that struct doesn't have the type D. Like this: pub struct Something<D: SomeTraitYouNeed>{ ... } The struct has the generic marker D, but it doesn't have any of its attributes that follow the requirements of D. This will confuse the compiler because it will not be sure of how to apply the trait rules. In that case we create a PhantomData that implements those rules: pub struct Something<D: SomeTraitYouNeed> { PhantomData<D>, .... } PhantomData is just to fulfill the rules of the compiler, it will not exist in the compiled source code. Edit: Here is an example of a use for this. I once created a Worker struct for running custom functions in multi-threaded environments. It requires a trait for the parameter of the function, and another for the function it is going to run. It stores the parameters of the function, so that is okay. It doesn't store any attribute that implement the trait of the function it is going to execute. Due to that, I needed to implement a PhantomData for the function it is going to execute. Edit: For those unfamiliar with Rust. Traits are interfaces. Or, in simpler terms, a "class" with only functions. A generic is a "type that implement ("inherit") a certain trait ("Interface").
27:46 that's why its german, ITS OVERENGINEERED
The whole article is just kind of wrestling with the semantics of the language lol
In this case PhantomData is there mostly because of variance, the struct is now covariant to T because it is naturally covariant to PhantomData<T>. To explain variance: There exist three types if variance. Covariant<T>: 'a if T: 'a // a restriction in T leads to a restriction in Covariant<T> Invariant<T> if T: 'a // a restriction in T does nothing to Invariant<T> 'a: Contravariant<T> if T: 'a // a restriction in T loosens restrictions in Contravariant<T> Examples on how to make those types: struct Covariant<T>(T); struct Invariant<T>(*T); struct Contravariant<T>(fn()->T);
Reminds me of strings is Pascal
What? Polars the python library is written Rust. They are not two separate things.
I really like those type of videos.
gotta optimize that Rust weapon handling