Created
August 9, 2020 13:42
-
-
Save robertohuertasm/dbca7161880b9298cb32c8b7de81ecf8 to your computer and use it in GitHub Desktop.
Downcasting rust -- error downcasting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::any::Any; | |
/// Method that can be use to safely downcast impl Responder to a specific type T | |
/// It returns a reference of type T | |
pub fn downcast<T>(responder: &dyn Any) -> Option<&T> | |
where | |
T: Responder + 'static, | |
{ | |
responder.downcast_ref::<T>() | |
} | |
/// Method that can be use to safely downcast impl Responder to a specific type T | |
/// It returns a mutable reference of type T | |
pub fn downcast_mut<T>(responder: &mut dyn Any) -> Option<&mut T> | |
where | |
T: Responder + 'static, | |
{ | |
responder.downcast_mut::<T>() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment