File:Crust of Rust- Subtyping and Variance.webm

Summary

Description
English: In this episode of Crust of Rust, we go over subtyping and variance — a niche part of Rust that most people don't have to think about, but which is deeply ingrained in some of Rust's borrow ergonomics, and occasionally manifests in confusing ways. In particular, we explore how trying to implement the relatively straightforward `strtok` function from C/C++ in Rust quickly lands us in a place where the function is more or less impossible to call due to variance!

0:00:00 Introduction 0:02:30 Practical variance in strtok 0:07:41 A simple strtok test 0:09:45 Implementing strtok 0:13:00 Why can't we call strtok? 0:17:26 Pretending to be the compiler 0:19:03 Shortening lifetimes 0:25:40 Subtypes 0:29:12 Covariance 0:33:15 Contravariance 0:42:14 Invariance 0:50:00 &'a mut T covariance in 'a 0:57:57 What went wrong in our strtok test? 1:02:24 Fixing strtok 1:07:34 Why is 'b: 'a not needed? 1:09:08 Shortening &'a mut and NLL 1:10:11 Is 'b: 'a implied for &'a &'b? 1:12:54 Variance, PhantomData, and drop check 1:28:06 Reasons for changing variance 1:30:47 for{'a} and variance 1:31:51 Mutating through *const T 1:33:29 NonNull{T} 1:35:26 How we got here

You can read more about subtyping and variance in the Rust reference @ https://doc.rust-lang.org/nightly/reference/subtyping.html or in the Nomicon @ https://doc.rust-lang.org/nomicon/subtyping.html.


Live version with chat: https://www.youtube.com/watch?v=--wzpkTuCrA
Date
Source YouTube: Crust of Rust: Subtyping and Variance – View/save archived versions on archive.org and archive.todayCategory:Media from YouTube
Author Jon Gjengset

Licensing

This video, screenshot or audio excerpt was originally uploaded on YouTube under a CC BY license.
Their website states: "YouTube allows users to mark their videos with a Creative Commons CC BY license."
To the uploader: You must provide a link (URL) to the original file and the authorship information if available.
w:en:Creative Commons
attribution
This file is licensed under the Creative Commons Attribution 3.0 Unported license.
Attribution:
Jon Gjengset
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
Category:CC-BY-3.0#Crust%20of%20Rust-%20Subtyping%20and%20Variance.webm
Category:Media from YouTube#Crust%20of%20Rust-%20Subtyping%20and%20Variance.webm
This file, which was originally posted to an external website, has not yet been reviewed by an administrator or reviewer to confirm that the above license is valid. See Category:License review needed for further instructions.
Category:License review needed (video)#153340957 Category:Uploaded with video2commons Category:Videos of Rust (programming language)
Category:CC-BY-3.0 Category:License review needed (video) Category:Media from YouTube Category:Uploaded with video2commons Category:Videos of Rust (programming language)