[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
|
|
@ -2,12 +2,12 @@ use crate::{ContextRef, Error, Result, ValueRef};
|
|||
use std::num::TryFromIntError;
|
||||
|
||||
pub trait TryFromValue: Sized {
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, ctx: &ContextRef<'r>) -> Result<'r, Self>;
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self>;
|
||||
}
|
||||
|
||||
impl TryFromValue for u8 {
|
||||
#[inline]
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, ctx: &ContextRef<'r>) -> Result<'r, Self> {
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
let v = value.to_u32(&ctx)?;
|
||||
v.try_into()
|
||||
.map_err(|e: TryFromIntError| Error::ConversionError(e.to_string()))
|
||||
|
|
@ -16,7 +16,7 @@ impl TryFromValue for u8 {
|
|||
|
||||
impl TryFromValue for u16 {
|
||||
#[inline]
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, ctx: &ContextRef<'r>) -> Result<'r, Self> {
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
let v = value.to_u32(&ctx)?;
|
||||
v.try_into()
|
||||
.map_err(|e: TryFromIntError| Error::ConversionError(e.to_string()))
|
||||
|
|
@ -25,21 +25,21 @@ impl TryFromValue for u16 {
|
|||
|
||||
impl TryFromValue for u32 {
|
||||
#[inline]
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, ctx: &ContextRef<'r>) -> Result<'r, Self> {
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
value.to_u32(&ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// impl<'c,'d> TryFrom<&'c ValueRef<'d>> for u64 {
|
||||
// #[inline]
|
||||
// fn try_from_value<'r>(value: &ValueRef<'r>, ctx:&ContextRef<'r>) -> Result<'r, Self> {
|
||||
// fn try_from_value(value: &ValueRef, ctx:&ContextRef) -> Result< Self> {
|
||||
// value.to_u64()
|
||||
// }
|
||||
// }
|
||||
|
||||
impl TryFromValue for i8 {
|
||||
#[inline]
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, ctx: &ContextRef<'r>) -> Result<'r, Self> {
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
let v = value.to_i32(&ctx)?;
|
||||
v.try_into()
|
||||
.map_err(|e: TryFromIntError| Error::ConversionError(e.to_string()))
|
||||
|
|
@ -48,7 +48,7 @@ impl TryFromValue for i8 {
|
|||
|
||||
impl TryFromValue for i16 {
|
||||
#[inline]
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, ctx: &ContextRef<'r>) -> Result<'r, Self> {
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
let v = value.to_i32(&ctx)?;
|
||||
v.try_into()
|
||||
.map_err(|e: TryFromIntError| Error::ConversionError(e.to_string()))
|
||||
|
|
@ -57,21 +57,21 @@ impl TryFromValue for i16 {
|
|||
|
||||
impl TryFromValue for i32 {
|
||||
#[inline]
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, ctx: &ContextRef<'r>) -> Result<'r, Self> {
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
value.to_i32(&ctx)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFromValue for i64 {
|
||||
#[inline]
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, ctx: &ContextRef<'r>) -> Result<'r, Self> {
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
value.to_i64(&ctx)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFromValue for f32 {
|
||||
#[inline]
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, ctx: &ContextRef<'r>) -> Result<'r, Self> {
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
let v = value.to_float64(&ctx)?;
|
||||
Ok(v as f32)
|
||||
}
|
||||
|
|
@ -79,21 +79,21 @@ impl TryFromValue for f32 {
|
|||
|
||||
impl TryFromValue for f64 {
|
||||
#[inline]
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, ctx: &ContextRef<'r>) -> Result<'r, Self> {
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
value.to_float64(&ctx)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFromValue for bool {
|
||||
#[inline]
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, _ctx: &ContextRef<'r>) -> Result<'r, Self> {
|
||||
fn try_from_value(value: &ValueRef, _ctx: &ContextRef) -> Result<Self> {
|
||||
value.to_bool()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFromValue for String {
|
||||
#[inline]
|
||||
fn try_from_value<'r>(value: &ValueRef<'r>, ctx: &ContextRef<'r>) -> Result<'r, Self> {
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
value.to_string(&ctx)
|
||||
}
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ impl TryFromValue for String {
|
|||
// impl<'c, T: Class> TryFrom<&'c ValueRef<'_>> for T {
|
||||
//
|
||||
// #[inline]
|
||||
// fn try_from_value<'r>(value: &ValueRef<'r>, ctx:&ContextRef<'r>) -> Result<'r, Self> {
|
||||
// fn try_from_value(value: &ValueRef, ctx:&ContextRef) -> Result< Self> {
|
||||
// T::from_value(value)
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue