use std::result;
use std::error::Error;
pub fn new<T>(x: T) -> Box<T> {
Box::new(x)
}
pub type GError = Box<Error>;
pub type GResult<T> = result::Result<T, GError>;
pub type Void = GResult<()>;
pub struct FinishedFlag(pub bool);
impl FinishedFlag {
pub fn is_finished(&self) -> bool {
return self.0
}
pub fn finish(&mut self) {
assert!(!self.is_finished());
self.set_finished();
}
pub fn set_finished(&mut self) {
self.0 = true;
}
}
impl Drop for FinishedFlag {
fn drop(&mut self) {
assert!(self.is_finished());
}
}
use std::sync::Arc;
use std::sync::Mutex;
pub fn newArcMutex<T>(x: T) -> Arc<Mutex<T>> {
Arc::new(Mutex::new(x))
}
use std::rc::Rc;
use std::cell::RefCell;
pub fn unwrap_Rc_RefCell<T>(this: Rc<RefCell<T>>) -> T {
let ures : result::Result<RefCell<_>, _> = Rc::try_unwrap(this);
match ures {
Ok(refCell) => return refCell.into_inner(),
Err(_) => panic!("std::Rc unwrap failed")
}
}