Skip to content

Commit

Permalink
Add Object::as_inner
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Nov 25, 2022
1 parent ba6aab0 commit a605058
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/fj-kernel/src/objects/object.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::any::Any;

use crate::{
insert::Insert,
objects::{
Expand All @@ -23,6 +25,23 @@ macro_rules! object {
)*
}

impl<F: Form> Object<F> {
/// Convert the `Object` into the requested inner type
pub fn as_inner<T>(&self) -> Option<&F::Form<T>>
where
Self: 'static,
F::Form<T>: Any,
{
match self {
$(
Self::$ty(object) =>
(object as &dyn Any).downcast_ref(),

)*
}
}
}

impl Object<WithHandle> {
/// Insert the object into its respective store
pub fn insert(
Expand Down

0 comments on commit a605058

Please sign in to comment.