39
submitted 1 year ago by hatchet@sh.itjust.works to c/rust@lemmy.ml

Whenever I encounter an interesting Rust programming technique, I add it to this blog post. I've amassed a bit of a collection. Hopefully someone finds it interesting and useful!

you are viewing a single comment's thread
view the rest of the comments
[-] internetionals@toot.community 0 points 1 year ago

@calcopiritus @hatchet That way you can pass a reference or anything that can be turned into a reference as an argument. So the caller can supply a &T, Box, Rc, Arc, … (I dont’t know if there is a blanket impl so that even T itself will work.

[-] hatchet@sh.itjust.works 1 points 1 year ago

Well, actually I would tend to agree that &[T] is preferable to AsRef in most cases; all of the smart pointers you mentioned can also easily be turned into plain references. I probably could have chosen a better example.

this post was submitted on 26 Jul 2023
39 points (97.6% liked)

Rust Programming

7734 readers
1 users here now

founded 5 years ago
MODERATORS