Use PackedOption<Value> instead of NO_VALUE.

- Remove NO_VALUE and ExpandedValue::None.
- Remove the Default implelmentation for Value.
- InstructionData::second_result() returns an Option<Value>.
- InstructionData::second_result() returns a reference to the packed
  option.
This commit is contained in:
Jakob Stoklund Olesen
2017-01-19 15:52:29 -08:00
parent 1389a51c7a
commit 0d77b19708
7 changed files with 97 additions and 104 deletions

View File

@@ -8,6 +8,7 @@
//! to represent `None`.
use std::fmt;
use std::mem;
/// Types that have a reserved value which can't be created any other way.
pub trait ReservedValue: Eq {
@@ -46,6 +47,11 @@ impl<T: ReservedValue> PackedOption<T> {
pub fn unwrap(self) -> T {
self.expand().unwrap()
}
/// Takes the value out of the packed option, leaving a `None` in its place.
pub fn take(&mut self) -> Option<T> {
mem::replace(self, None.into()).expand()
}
}
impl<T: ReservedValue> Default for PackedOption<T> {