Today I was trying to write polymorphic error handling in Rust, something achievable with dynamic_cast
in C++, and incredibly easy in Go. In Rust, of course, it’s overcomplicated.
After a couple frustrating hours of searching with no success, I stumbled upon the downcast_ref
method of the Error
trait, which finally allowed me to write what I wanted. Oddly enough, I couldn’t find this solution anywhere.
Note that the String
concrete type cannot be retrieved.
Playground link here.
1 comment:
Great content! Super high-quality! If you want to learn more about PHP, you can learn from here -
How to display PDF file in PHP from database
How to read CSV file in PHP and store in MySQL
Create and Download Word document PHP
NodeJS Introduction
Node js Installation
Run Node js Application
Node js HTTP Module
Post a Comment