[oden] The big lifetime removal
It turns out that rust can't really reason about the relationship between the runtime lifetime and the context lifetime in a way that is actually usable. This removes the lifetime stuff in favor of reference counting the runtime itself, via a block that we embed in the pointer. This, I think, it the least worst option here.
This commit is contained in:
parent
898b1fe129
commit
9f808cea31
10 changed files with 269 additions and 312 deletions
|
|
@ -61,7 +61,7 @@ impl fmt::Debug for ClassID {
|
|||
pub trait Class: Sized {
|
||||
fn class_id() -> &'static ClassID;
|
||||
|
||||
fn into_value<'r>(self, context: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
fn into_value(self, context: &ContextRef) -> ValueResult {
|
||||
let class_id = Self::class_id();
|
||||
|
||||
// Check to see if the class is registered with the runtime. If not,
|
||||
|
|
@ -122,7 +122,7 @@ pub trait Class: Sized {
|
|||
Ok(val)
|
||||
}
|
||||
|
||||
fn try_from_value_mut<'r>(value: &ValueRef<'r>) -> Result<'r, RefMut<'r, Self>> {
|
||||
fn try_from_value_mut<'a>(value: &'a ValueRef) -> Result<RefMut<'a, Self>> {
|
||||
let class = Self::class_id();
|
||||
|
||||
// SAFETY: value.val is known to be valid, from the ValueRef.
|
||||
|
|
@ -139,11 +139,11 @@ pub trait Class: Sized {
|
|||
.borrow_mut())
|
||||
}
|
||||
|
||||
fn from_value_mut<'r>(value: &ValueRef<'r>) -> RefMut<'r, Self> {
|
||||
fn from_value_mut<'a>(value: &'a ValueRef) -> RefMut<'a, Self> {
|
||||
Self::try_from_value_mut(value).expect("Wrong type for value")
|
||||
}
|
||||
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>) -> Result<'r, Ref<'r, Self>> {
|
||||
fn try_from_value<'a>(value: &'a ValueRef) -> Result<Ref<'a, Self>> {
|
||||
let class = Self::class_id();
|
||||
|
||||
// SAFETY: value.val is known to be valid, from the ValueRef.
|
||||
|
|
@ -160,7 +160,7 @@ pub trait Class: Sized {
|
|||
.borrow())
|
||||
}
|
||||
|
||||
fn from_value<'r>(value: &ValueRef<'r>) -> Ref<'r, Self> {
|
||||
fn from_value<'a>(value: &'a ValueRef) -> Ref<'a, Self> {
|
||||
match Self::try_from_value(value) {
|
||||
Ok(r) => r,
|
||||
Err(_) => panic!(
|
||||
|
|
@ -171,7 +171,7 @@ pub trait Class: Sized {
|
|||
}
|
||||
}
|
||||
|
||||
fn prototype<'r>(context: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
fn prototype(context: &ContextRef) -> ValueResult {
|
||||
context.new_object()
|
||||
}
|
||||
|
||||
|
|
@ -192,7 +192,7 @@ pub trait Class: Sized {
|
|||
/// collector won't collect it.
|
||||
fn mark<F>(&self, _mark: F)
|
||||
where
|
||||
F: for<'r> Fn(&ValueRef<'r>) -> (),
|
||||
F: Fn(&ValueRef) -> (),
|
||||
{
|
||||
// By default, nothing.
|
||||
}
|
||||
|
|
@ -268,7 +268,7 @@ mod tests {
|
|||
#[test]
|
||||
fn round_trips() {
|
||||
let rt = Runtime::new();
|
||||
let ctx = Context::new(&rt);
|
||||
let ctx = Context::new(rt);
|
||||
|
||||
let x = X { x: 76 };
|
||||
let val = x.into_value(&ctx).expect("Unable to create value!");
|
||||
|
|
@ -280,7 +280,7 @@ mod tests {
|
|||
#[test]
|
||||
fn double_create() {
|
||||
let rt = Runtime::new();
|
||||
let ctx = Context::new(&rt);
|
||||
let ctx = Context::new(rt);
|
||||
|
||||
let x = X { x: 76 };
|
||||
let _v1 = x.into_value(&ctx).expect("Unable to create value!");
|
||||
|
|
@ -292,7 +292,7 @@ mod tests {
|
|||
#[test]
|
||||
fn bad_class_id() {
|
||||
let rt = Runtime::new();
|
||||
let ctx = Context::new(&rt);
|
||||
let ctx = Context::new(rt);
|
||||
|
||||
let y = Y { y: 110 };
|
||||
let val = y.into_value(&ctx).expect("Unable to create value!");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue