-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
90 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::any::Any; | ||
|
||
use dev_util::downcast_ref_or_panic; | ||
use pie::trait_object::{KeyObj, ValueObj}; | ||
|
||
/// Downcast trait objects to specific types for testing purposes. | ||
pub trait Downcast { | ||
fn downcast<T: Any>(&self) -> &T; | ||
|
||
fn as_str(&self) -> &'static str { | ||
*self.downcast::<&'static str>() | ||
} | ||
fn as_result_str<E: Any>(&self) -> &Result<&'static str, E> { | ||
self.downcast::<Result<&'static str, E>>() | ||
} | ||
|
||
fn as_string(&self) -> &String { | ||
self.downcast::<String>() | ||
} | ||
fn as_result_string<E: Any>(&self) -> &Result<String, E> { | ||
self.downcast::<Result<String, E>>() | ||
} | ||
} | ||
|
||
impl Downcast for dyn ValueObj { | ||
fn downcast<T: Any>(&self) -> &T { downcast_ref_or_panic::<T>(self.as_any()) } | ||
} | ||
impl Downcast for Box<dyn ValueObj> { | ||
fn downcast<T: Any>(&self) -> &T { downcast_ref_or_panic::<T>(self.as_ref().as_any()) } | ||
} | ||
|
||
impl Downcast for dyn KeyObj { | ||
fn downcast<T: Any>(&self) -> &T { downcast_ref_or_panic::<T>(self.as_any()) } | ||
} | ||
impl Downcast for Box<dyn KeyObj> { | ||
fn downcast<T: Any>(&self) -> &T { downcast_ref_or_panic::<T>(self.as_ref().as_any()) } | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod task; | ||
|
||
pub mod downcast; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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