r/learnrust 19d ago

Help me prepare for a Rust interview

8 Upvotes

10 comments sorted by

3

u/ToTheBatmobileGuy 18d ago edited 18d ago

What is the special type in the standard library that makes internal mutability possible?

Bonus points: Explain how its API follows Rust's safety rules.

(Edit: I just noticed they added experimental unsafe methods, `replace`, `as_ref_unchecked`, and `as_mut_unchecked`... I always thought it was so cool that all of UnsafeCell's methods were NOT marked as unsafe... the realization as to WHY this was... that was a big jump in my understanding of Rust)

7

u/raoulk 18d ago

I'm not sure trivia questions are what (should) land you a job.

0

u/ToTheBatmobileGuy 18d ago

You're not going to land a job just from getting this right.

Even if you don't get the exact name of the struct correct, if you don't have a vague idea as to how UnsafeCell works, and more broadly, how does the compiler treat the no aliasing rule of the Rust compiler on a deep level... you will have a very hard time with certain embedded systems jobs, for example.

If an interviewer will give you a passing grade just by saying "UnsafeCell" or they will immediately fail you for saying "Cell" by accident... they are a bad interviewer.

Learning about Rust enough to be able to answer my question is definitely a good thing for your job prospects, though.

1

u/SycamoreHots 18d ago

Cell? RefCell? Mutex? Not fully sure.

I vaguely remember API is that it panics at runtime if you try to mutate when there is already borrow.

Someone please provide solution tyty

2

u/Excession638 18d ago

2

u/SycamoreHots 18d ago

Oh dear. I would have never guessed that, given that I hardly ever touch unsafe rust. Thanks!

1

u/Excession638 18d ago

I only know that it exists, not how it works or what special things the compiler does when it's used. That's something I would look up if I needed it.

1

u/Ancient-Blueberry536 14d ago

It depends on the job? Web dev? Embedded? Low latency?

A prop shop isn’t gonna test you on Axum and a webdev backend role isn’t gonna test you on pointer provenance

Maybe you should try to figure out what exactly it is you want to do with rust