[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:
John Doty 2023-06-19 08:28:26 -07:00
parent 898b1fe129
commit 9f808cea31
10 changed files with 269 additions and 312 deletions

View file

@ -1,110 +1,110 @@
use crate::{Class, ContextRef, Error, Value, ValueRef, ValueResult};
pub trait TryIntoValue<'r> {
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r>;
pub trait TryIntoValue {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult;
}
impl<'r> TryIntoValue<'r> for u8 {
impl TryIntoValue for u8 {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_u64(self)
}
}
impl<'r> TryIntoValue<'r> for u16 {
impl TryIntoValue for u16 {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_u64(self)
}
}
impl<'r> TryIntoValue<'r> for u32 {
impl TryIntoValue for u32 {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_u64(self)
}
}
impl<'r> TryIntoValue<'r> for u64 {
impl TryIntoValue for u64 {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_u64(self)
}
}
impl<'r> TryIntoValue<'r> for i8 {
impl TryIntoValue for i8 {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_i32(self)
}
}
impl<'r> TryIntoValue<'r> for i16 {
impl TryIntoValue for i16 {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_i32(self)
}
}
impl<'r> TryIntoValue<'r> for i32 {
impl TryIntoValue for i32 {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_i32(self)
}
}
impl<'r> TryIntoValue<'r> for i64 {
impl TryIntoValue for i64 {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_i64(self)
}
}
impl<'r> TryIntoValue<'r> for f32 {
impl TryIntoValue for f32 {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_f64(self)
}
}
impl<'r> TryIntoValue<'r> for f64 {
impl TryIntoValue for f64 {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_f64(self)
}
}
impl<'r> TryIntoValue<'r> for bool {
impl TryIntoValue for bool {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_bool(self)
}
}
impl<'r> TryIntoValue<'r> for &str {
impl TryIntoValue for &str {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
ctx.new_string(self)
}
}
impl<'r> TryIntoValue<'r> for &ValueRef<'r> {
impl TryIntoValue for &ValueRef {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
Ok(self.dup(ctx))
}
}
impl<'r> TryIntoValue<'r> for Value<'r> {
impl TryIntoValue for Value {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
Ok(self.dup(ctx))
}
}
impl<'r> TryIntoValue<'r> for Error<'r> {
impl TryIntoValue for Error {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
match self {
Error::TooManyClasses => Err(Error::TooManyClasses),
Error::WrongClass(c) => Err(Error::WrongClass(c)),
@ -121,9 +121,9 @@ impl<'r> TryIntoValue<'r> for Error<'r> {
}
}
impl<'r, T: Class> TryIntoValue<'r> for T {
impl<T: Class> TryIntoValue for T {
#[inline]
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
self.into_value(ctx)
}
}