6

"Type-Driven API Design in Rust" by Will Crichton

 2 years ago
source link: https://www.youtube.com/watch?v=bnnacleqg6k
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
ST. LOUIS

"Type-Driven API Design in Rust" by Will Crichton

Rust is a unique programming language that blends imperative and functional concepts to make low-level systems safer. However, compared to other modern languages, designing APIs in Rust requires a fundamentally different mindset -- for example, designing without classes or inheritance. In this talk, I will live-code the design of a simple Rust API. Through the evolution of the API, I will demonstrate how Rust’s type system (especially traits) can be used to design interfaces that cleanly compose with existing code, and that help API clients catch mistakes at compile-time.

Will Crichton Stanford University @wcrichton

Will Crichton is a 6th year CS Ph.D. student at Stanford University advised by Profs. Pat Hanrahan and Maneesh Agrawala. His research is about applying cognitive psychology and programming language theory to understand programmers and to design better programming tools.

Recorded at Strange Loop 2021 https://thestrangeloop.com

Show lessShow more

19 Comments

Sort by
default-user=s48-c-k-c0x00ffffff-no-rj
Add a public comment...
this talk is so well thought out, you seem to know every question that the audience may have

1 week ago (edited)

This is a great talk. Another great feature of the API presented here is that it works ergonomically out of the box for operations that need references, mutable references and ownership just by changing the Iterator that you send in to Progress - i.e. .iter() vs. iter_mut() vs. into_iter(), the Progress implementation itself is completely agnostic of T.

The compile-time error messages can be an issue if you use crates that use this approach a lot though (as well as understanding all of the "helper" types like Bounded/Unbounded here, when there are dozens of them). It'd be nice if there were a way to add a custom compile-time error to a type in your library crate, matching against specific error types. e.g. if someone tries to call with_delims on the Unbounded case, it could print an additional final error message mentioning the difference and a link to the relevant docs.

Read more 1 week ago

Wow thanks Will, excellent communicator! The type state thing in relation to rocket for starting up a web server... can't tell you how many hours I've seen people (myself included) waste in web backends accidentally messing up order of things

1 week ago

Very cool talk! Feel like I’ve got a much better idea of how to utilize traits and leverage the type system in a more-than-superficial way now.

1 week ago


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK