Uploaded January 2023 | Updated November 2026, 3 hours ago
Rust Programming Tutorial for the TypeState builder pattern. We will also learn how to use PhantomData as one of the states.
Help support this channel ► patreon.com/jeremychone
Previous Video on builder pattern: youtube.com/watch?v=Z_3WOSiYYFY&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
GitHub source (with the other builder patterns): github.com/jeremychone-channel/rust-builder
Some Notes:
1) PhantomData are erased by the compiler, meaning they do not exist at "runtime" but allow code to use them to leverage the compiler's type system.
2) As commented by 'Harold Ruiter,' the 'build()' method has become infallible, meaning it cannot fail, and therefore, it can just return 'Request', rather than Result of Request.
3) The TypeState pattern does not have to be used only with the builder pattern.
4) As mentioned in the video, generics increase the binary size and compile time. While, more often than not, generics' value outweighs those costs, there is still a point of diminishing return if generics are overused.
5) To follow the #4 point, in this tutorial, we showed the multi states pattern with URL and Method, but designing a builder with too many states, for each property, for example, would be overkill and have counter-productive side effects.
6) In theory, the pure definition of the TypeState pattern assumes the same type is returned, which is technically not feasible in Rust, as Generic creates a different type. However, from a practical Rust perspective, this is a good representation of the TypeState pattern.
Thanks to Sergey Potapov's great blog post on "Builder with typestate in Rust" (greyblake.com/blog/builder-with-typestate-in-rust/)
Jeremy Chone:
- Twitter - twitter.com/jeremychone
- Discord On Rust - discord.gg/W2besKCzjx
- AWESOME-APP - https://awesomeapp.dev - Rust Templates for building awesome applications.
- Patreon - patreon.com/jeremychone - Any help is a big help (for Rust educational content)
Other popular Rust Programming videos:
- Rust Builder Pattern - youtube.com/watch?v=Z_3WOSiYYFY&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Quick Start Code Layout - youtube.com/watch?v=oxx7MmN4Ib0&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- AWESOME-APP Full Overview - Rust template for building Awesome Desktop Application: youtube.com/watch?v=BY_ZjPGqJJk&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Tauri Quick Introduction (Desktop App wit Rust Programming): youtube.com/watch?v=kRoGYgAuZQE&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Rust Web App tutorials series: youtube.com/watch?v=VIig9IcQ-w8&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q&list=PL7r-PXl6ZPcCLvwpdD2Vj1O4CyoFTiHKd
- Rust Bevy Full Tutorial - Game Development with Rust: youtube.com/watch?v=j7qHwb7geIM&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Rust for Java Developers series: youtube.com/watch?v=iFdh4sPC5Tg&list=PL7r-PXl6ZPcD63DS2djSiz4SlXkaTfobc&index=2&t=654s
Playlists:
- Rust For Desktop App: youtube.com/playlist?list=PL7r-PXl6ZPcAQAi1lfVrtHCSbaJbwZ4O8
- Everything Rust Programming - Tutorials, Courses, Tips, Examples: youtube.com/playlist?list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Rust Programming for Web Development: youtube.com/playlist?list=PL7r-PXl6ZPcCLvwpdD2Vj1O4CyoFTiHKd
- Rust Courses: youtube.com/playlist?list=PL7r-PXl6ZPcB4jn1_VR3D8tSK9DxOaiQE
- Rust for Java Developers: youtube.com/playlist?list=PL7r-PXl6ZPcD63DS2djSiz4SlXkaTfobc
Other notes:
- Tool used to do the green lines. ScreenBrush on Mac App Store (Gromit seems to be the equivalent on Linux)
- Edited with Davinci Resolve.
Rust Programming Tutorial for the TypeState builder pattern. We will also learn how to use PhantomData as one of the states.
Help support this channel ► patreon.com/jeremychone
Previous Video on builder pattern: youtube.com/watch?v=Z_3WOSiYYFY&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
GitHub source (with the other builder patterns): github.com/jeremychone-channel/rust-builder
Some Notes:
1) PhantomData are erased by the compiler, meaning they do not exist at "runtime" but allow code to use them to leverage the compiler's type system.
2) As commented by 'Harold Ruiter,' the 'build()' method has become infallible, meaning it cannot fail, and therefore, it can just return 'Request', rather than Result of Request.
3) The TypeState pattern does not have to be used only with the builder pattern.
4) As mentioned in the video, generics increase the binary size and compile time. While, more often than not, generics' value outweighs those costs, there is still a point of diminishing return if generics are overused.
5) To follow the #4 point, in this tutorial, we showed the multi states pattern with URL and Method, but designing a builder with too many states, for each property, for example, would be overkill and have counter-productive side effects.
6) In theory, the pure definition of the TypeState pattern assumes the same type is returned, which is technically not feasible in Rust, as Generic creates a different type. However, from a practical Rust perspective, this is a good representation of the TypeState pattern.
Thanks to Sergey Potapov's great blog post on "Builder with typestate in Rust" (greyblake.com/blog/builder-with-typestate-in-rust/)
Jeremy Chone:
- Twitter - twitter.com/jeremychone
- Discord On Rust - discord.gg/W2besKCzjx
- AWESOME-APP - https://awesomeapp.dev - Rust Templates for building awesome applications.
- Patreon - patreon.com/jeremychone - Any help is a big help (for Rust educational content)
Other popular Rust Programming videos:
- Rust Builder Pattern - youtube.com/watch?v=Z_3WOSiYYFY&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Quick Start Code Layout - youtube.com/watch?v=oxx7MmN4Ib0&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- AWESOME-APP Full Overview - Rust template for building Awesome Desktop Application: youtube.com/watch?v=BY_ZjPGqJJk&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Tauri Quick Introduction (Desktop App wit Rust Programming): youtube.com/watch?v=kRoGYgAuZQE&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Rust Web App tutorials series: youtube.com/watch?v=VIig9IcQ-w8&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q&list=PL7r-PXl6ZPcCLvwpdD2Vj1O4CyoFTiHKd
- Rust Bevy Full Tutorial - Game Development with Rust: youtube.com/watch?v=j7qHwb7geIM&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Rust for Java Developers series: youtube.com/watch?v=iFdh4sPC5Tg&list=PL7r-PXl6ZPcD63DS2djSiz4SlXkaTfobc&index=2&t=654s
Playlists:
- Rust For Desktop App: youtube.com/playlist?list=PL7r-PXl6ZPcAQAi1lfVrtHCSbaJbwZ4O8
- Everything Rust Programming - Tutorials, Courses, Tips, Examples: youtube.com/playlist?list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Rust Programming for Web Development: youtube.com/playlist?list=PL7r-PXl6ZPcCLvwpdD2Vj1O4CyoFTiHKd
- Rust Courses: youtube.com/playlist?list=PL7r-PXl6ZPcB4jn1_VR3D8tSK9DxOaiQE
- Rust for Java Developers: youtube.com/playlist?list=PL7r-PXl6ZPcD63DS2djSiz4SlXkaTfobc
Other notes:
- Tool used to do the green lines. ScreenBrush on Mac App Store (Gromit seems to be the equivalent on Linux)
- Edited with Davinci Resolve.





![Rust to Redis with Async/Await [Intermediate]
Gist link: https://gist.github.com/dfbd64d82b9d64fb30dc57e60a54457a
Quick code walkthrough for Rust Redis communication with Rust/Tokio async/await for Single-Threaded Concurrency!!! RustLang by Example
At the end, we see how making the program single-threaded still allows for concurrency. #RustLang #Rocks !
#RustRedis #Redis #RustLang #AsyncAwait #Concurrency #RustForFullStack
Other popular Rust Programming videos:
- Desktop Applicatin Code Rust Programming template full Overview: https://www.youtube.com/watch?v=BY_ZjPGqJJk&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Tauri Quick Introduction (Desktop App wit Rust Programming): https://www.youtube.com/watch?v=kRoGYgAuZQE&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Rust Web App tutorials series: https://www.youtube.com/watch?v=VIig9IcQ-w8&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q&list=PL7r-PXl6ZPcCLvwpdD2Vj1O4CyoFTiHKd
- Rust Bevy Full Tutorial - Game Development with Rust: https://www.youtube.com/watch?v=j7qHwb7geIM&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Rust for Java Developers series: https://www.youtube.com/watch?v=iFdh4sPC5Tg&list=PL7r-PXl6ZPcD63DS2djSiz4SlXkaTfobc&index=2&t=654s
Playlists:
- Rust For Desktop App: https://youtube.com/playlist?list=PL7r-PXl6ZPcAQAi1lfVrtHCSbaJbwZ4O8
- Everything Rust Programming - Tutorials, Courses, Tips, Examples: https://youtube.com/playlist?list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
- Rust Programming for Web Development: https://youtube.com/playlist?list=PL7r-PXl6ZPcCLvwpdD2Vj1O4CyoFTiHKd
- Rust Courses: https://youtube.com/playlist?list=PL7r-PXl6ZPcB4jn1_VR3D8tSK9DxOaiQE
- Furst for Java Developers: https://youtube.com/playlist?list=PL7r-PXl6ZPcD63DS2djSiz4SlXkaTfobc Rust to Redis with Async/Await [Intermediate]](https://i.ytimg.com/vi/uD5hBVHwyDM/mqdefault.jpg)

![Crate release Best Practice (publish = false for WIP)
My Rust Programming Cargo pattern for work-in-progress crates.
I used to mark unreleased versions as 0.7.4-WIP. The problem: thats a semver pre-release, so a dependent crate asking for genai 0.7.3 wont match it, and [patch.crates-io] gets silently ignored.
This isnt specific to -WIP. Any pre-release suffix, like -alpha, -beta, -rc.1 or -dev, has the same effect: Cargo wont match it against a normal version requirement unless the dependent explicitly asks for that pre-release. So a git patch with a pre-release version is skipped.
The fix:
- Keep the real next version: e.g., version = 0.7.4
- Add publish = false # WIP so it cant be published by accident
- Remove or comment out that line when you cut the release
Now the git patch matches, and the whole dependency tree uses one copy of the crate.
Then I show how I use this in my production Rust lib (genai) and CLI (aipack).
By the way, my consulting company now focuses on helping teams ship production Rust.
➜ https://britesnow.com
(15 years of production expertise, brought to your team)
Links related to this video:
➜ genai: https://github.com/jeremychone/rust-genai
➜ aipack: https://aipack.ai
➜ https://britesnow.com
More Links
➜ Helping teams ship production Rust - https://britesnow.com
(15 years of production coding expertise, brought to your team)
➜ pro@coder tutorial (current JC coding harness)
https://news.aipack.ai/p/procoder-v052-demo-workbench
➜ JC Twitter - https://twitter.com/jeremychone
➜ Discord JC general-rust - https://discord.gg/W2besKCzjx
➜ Discord JC Live Streaming - https://discord.gg/nEnG4ryBku
➜ Discord JC genai & aipack & procoder - https://discord.gg/6KkpQBKGFS Crate release Best Practice (publish = false for WIP)](https://i.ytimg.com/vi/unXTyeMxMYI/mqdefault.jpg)


