[parser, types] Add Obj::take() and use it to take the Obj from the parser when it is done

This commit is contained in:
Eryn Wells 2018-08-23 18:04:04 -07:00
parent 929846152e
commit 8e9fde7a9f
2 changed files with 8 additions and 1 deletions

View file

@ -13,6 +13,7 @@
//! available types in Scheme. These predicates are implemented as `is_*`
//! methods in a bunch of `Is*` traits defined below.
use std::mem;
use std::any::Any;
use std::fmt;
use super::*;
@ -36,6 +37,10 @@ impl Obj {
Obj::Ptr(Box::new(obj))
}
pub fn take(&mut self) -> Obj {
mem::replace(self, Obj::Null)
}
pub fn unbox_as<T: 'static + Object>(&self) -> Option<&T> {
match self {
Obj::Null => None,