use crate::object::{self as o, box_, dec, dec_ref, inc, Obj};
use std::marker::PhantomData;
pub trait Repr: Copy {
fn into_object(self) -> Obj;
unsafe fn take(object: Obj) -> Self;
unsafe fn share(object: Obj) -> Self;
unsafe fn release(self);
unsafe fn retain(self) -> Self;
}
impl Repr for Obj {
#[inline(always)]
fn into_object(self) -> Obj {
self
}
#[inline(always)]
unsafe fn take(object: Obj) -> Obj {
object
}
#[inline(always)]
unsafe fn share(object: Obj) -> Obj {
inc(object);
object
}
#[inline(always)]
unsafe fn release(self) {
dec(self)
}
#[inline(always)]
unsafe fn retain(self) -> Obj {
inc(self);
self
}
}
pub trait Scalar: Repr {}
macro_rules! scalar_reprs {
($($ty:ty: |$value:ident| $boxed:expr, |$object:ident| $unboxed:expr;)*) => {$(
impl Repr for $ty {
#[inline(always)]
fn into_object(self) -> Obj {
let $value = self;
#[allow(unused_unsafe)]
unsafe {
$boxed
}
}
#[inline(always)]
unsafe fn take($object: Obj) -> $ty {
let value = $unboxed;
dec($object);
value
}
#[inline(always)]
unsafe fn share($object: Obj) -> $ty {
$unboxed
}
#[inline(always)]
unsafe fn release(self) {}
#[inline(always)]
unsafe fn retain(self) -> $ty {
self
}
}
impl Scalar for $ty {}
)*};
}
scalar_reprs! {
u8: |v| box_(v as usize), |x| o::unbox(x) as u8;
u16: |v| box_(v as usize), |x| o::unbox(x) as u16;
u32: |v| o::box_uint32(v), |x| o::unbox_uint32(x);
u64: |v| o::box_uint64(v), |x| o::unbox_uint64(x);
usize: |v| o::box_usize(v), |x| o::unbox_usize(x);
f64: |v| o::box_float(v), |x| o::unbox_float(x);
f32: |v| o::box_float32(v), |x| o::unbox_float32(x);
}
#[repr(transparent)]
pub struct Value<C: Codec>(C::Repr, PhantomData<C>);
impl<C: Codec> Value<C> {
#[inline(always)]
pub unsafe fn from_raw(repr: C::Repr) -> Value<C> {
Value(repr, PhantomData)
}
#[inline(always)]
pub fn from_scalar(repr: C::Repr) -> Value<C>
where
C::Repr: Scalar,
{
Value(repr, PhantomData)
}
#[inline(always)]
pub fn into_raw(self) -> C::Repr {
let repr = self.0;
std::mem::forget(self);
repr
}
#[inline(always)]
pub fn as_raw(&self) -> C::Repr {
self.0
}
#[inline(always)]
pub fn into_object(self) -> Obj {
self.into_raw().into_object()
}
#[inline(always)]
pub unsafe fn take(object: Obj) -> Value<C> {
Value(C::Repr::take(object), PhantomData)
}
#[inline(always)]
pub unsafe fn share(object: Obj) -> Value<C> {
Value(C::Repr::share(object), PhantomData)
}
#[inline(always)]
pub fn retain(&self) -> Value<C> {
Value(unsafe { self.0.retain() }, PhantomData)
}
#[inline(always)]
pub unsafe fn cast<D: Codec<Repr = C::Repr>>(self) -> Value<D> {
Value(self.into_raw(), PhantomData)
}
}
impl<C: Codec> Drop for Value<C> {
#[inline(always)]
fn drop(&mut self) {
unsafe { self.0.release() }
}
}
pub trait Codec: Sized {
type Rust;
type Repr: Repr;
fn into_lean(value: Self::Rust) -> Value<Self>;
fn to_lean(value: &Self::Rust) -> Value<Self>;
fn from_lean(value: Value<Self>) -> Self::Rust;
#[doc(hidden)]
unsafe fn lent(value: &Self::Rust) -> Value<Self> {
Self::to_lean(value)
}
fn lend<R>(value: &Value<Self>, f: impl FnOnce(&Self::Rust) -> R) -> R {
let copy = Self::from_lean(value.retain());
f(©)
}
}
pub trait KeptByLeanForAllThreads {}
impl<T: Sync> KeptByLeanForAllThreads for T {}
#[inline(always)]
pub fn returned_by_a_trusted_function<T: KeptByLeanForAllThreads>() {}
#[inline(always)]
pub fn given_to_a_lean_function<T: KeptByLeanForAllThreads>() {}
macro_rules! scalars {
($($name:ident: $rust:ty as $repr:ty, |$value:ident| $to:expr, |$raw:ident| $from:expr;)*) => {$(
#[doc = concat!("Lean's `", stringify!($name), "`.")]
pub struct $name;
impl Codec for $name {
type Rust = $rust;
type Repr = $repr;
#[inline(always)]
fn into_lean($value: $rust) -> Value<$name> {
Value::from_scalar($to)
}
#[inline(always)]
fn to_lean(value: &$rust) -> Value<$name> {
Self::into_lean(*value)
}
#[inline(always)]
fn from_lean(value: Value<$name>) -> $rust {
let $raw = value.into_raw();
$from
}
}
)*};
}
scalars! {
UInt8: u8 as u8, |v| v, |r| r;
UInt16: u16 as u16, |v| v, |r| r;
UInt32: u32 as u32, |v| v, |r| r;
UInt64: u64 as u64, |v| v, |r| r;
USize: usize as usize, |v| v, |r| r;
Int8: i8 as u8, |v| v as u8, |r| r as i8;
Int16: i16 as u16, |v| v as u16, |r| r as i16;
Int32: i32 as u32, |v| v as u32, |r| r as i32;
Int64: i64 as u64, |v| v as u64, |r| r as i64;
ISize: isize as usize, |v| v as usize, |r| r as isize;
Bool: bool as u8, |v| v as u8, |r| r != 0;
Char: char as u32, |v| v as u32, |r| crate::char_of_u32(r);
Float: f64 as f64, |v| v, |r| r;
Float32: f32 as f32, |v| v, |r| r;
}
pub struct Generic<'a, const N: usize>(PhantomData<&'a ()>);
impl<'a, const N: usize> Codec for Generic<'a, N> {
type Rust = crate::Generic<'a, N>;
type Repr = Obj;
#[inline]
fn into_lean(value: crate::Generic<'a, N>) -> Value<Self> {
unsafe { Value::from_raw(value.into_raw()) }
}
#[inline]
fn to_lean(value: &crate::Generic<'a, N>) -> Value<Self> {
Self::into_lean(value.clone())
}
#[inline]
fn from_lean(value: Value<Self>) -> crate::Generic<'a, N> {
unsafe { crate::Generic::from_raw(value.into_raw()) }
}
}
pub struct Unit;
impl Codec for Unit {
type Rust = ();
type Repr = Obj;
fn into_lean(_value: ()) -> Value<Unit> {
unsafe { Value::from_raw(box_(0)) }
}
fn to_lean(_value: &()) -> Value<Unit> {
unsafe { Value::from_raw(box_(0)) }
}
fn from_lean(_value: Value<Unit>) {}
}
pub struct Nat;
impl Codec for Nat {
type Rust = crate::Nat;
type Repr = Obj;
#[inline]
fn into_lean(value: crate::Nat) -> Value<Nat> {
unsafe { Value::from_raw(value.into_raw()) }
}
#[inline]
fn to_lean(value: &crate::Nat) -> Value<Nat> {
Self::into_lean(value.clone())
}
#[inline]
fn from_lean(value: Value<Nat>) -> crate::Nat {
unsafe { crate::Nat::owning(value.into_raw()) }
}
#[inline]
fn lend<R>(value: &Value<Nat>, f: impl FnOnce(&crate::Nat) -> R) -> R {
let nat = std::mem::ManuallyDrop::new(unsafe { crate::Nat::from_raw(value.as_raw()) });
f(&nat)
}
}
pub struct Int;
impl Codec for Int {
type Rust = crate::Int;
type Repr = Obj;
#[inline]
fn into_lean(value: crate::Int) -> Value<Int> {
unsafe { Value::from_raw(value.into_raw()) }
}
#[inline]
fn to_lean(value: &crate::Int) -> Value<Int> {
Self::into_lean(value.clone())
}
#[inline]
fn from_lean(value: Value<Int>) -> crate::Int {
unsafe { crate::Int::owning(value.into_raw()) }
}
#[inline]
fn lend<R>(value: &Value<Int>, f: impl FnOnce(&crate::Int) -> R) -> R {
let int = std::mem::ManuallyDrop::new(unsafe { crate::Int::from_raw(value.as_raw()) });
f(&int)
}
}
pub struct String;
impl Codec for String {
type Rust = std::string::String;
type Repr = Obj;
fn into_lean(value: std::string::String) -> Value<String> {
unsafe { Value::from_raw(crate::string::from_string(value)) }
}
fn to_lean(value: &std::string::String) -> Value<String> {
unsafe { Value::from_raw(crate::string::mk_string(value)) }
}
fn from_lean(value: Value<String>) -> std::string::String {
unsafe { crate::string::into_string(value.into_raw()) }
}
fn lend<R>(value: &Value<String>, f: impl FnOnce(&std::string::String) -> R) -> R {
f(unsafe { crate::string::held_string(value.as_raw()) })
}
}
pub struct ByteArray;
impl Codec for ByteArray {
type Rust = Vec<u8>;
type Repr = Obj;
fn into_lean(value: Vec<u8>) -> Value<ByteArray> {
unsafe { Value::from_raw(crate::sarray::byte_array_from_vec(value)) }
}
fn to_lean(value: &Vec<u8>) -> Value<ByteArray> {
Self::into_lean(value.clone())
}
fn from_lean(value: Value<ByteArray>) -> Vec<u8> {
unsafe { crate::sarray::byte_array_into_vec(value.into_raw()) }
}
fn lend<R>(value: &Value<ByteArray>, f: impl FnOnce(&Vec<u8>) -> R) -> R {
f(unsafe { crate::sarray::held_bytes(value.as_raw()) })
}
}
pub struct FloatArray;
impl Codec for FloatArray {
type Rust = Vec<f64>;
type Repr = Obj;
fn into_lean(value: Vec<f64>) -> Value<FloatArray> {
unsafe { Value::from_raw(crate::sarray::float_array_from_vec(value)) }
}
fn to_lean(value: &Vec<f64>) -> Value<FloatArray> {
Self::into_lean(value.clone())
}
fn from_lean(value: Value<FloatArray>) -> Vec<f64> {
unsafe { crate::sarray::float_array_into_vec(value.into_raw()) }
}
fn lend<R>(value: &Value<FloatArray>, f: impl FnOnce(&Vec<f64>) -> R) -> R {
f(unsafe { crate::sarray::held_floats(value.as_raw()) })
}
}
struct Owned(Vec<Obj>);
impl Owned {
fn into_vec(mut self) -> Vec<Obj> {
std::mem::take(&mut self.0)
}
}
impl Drop for Owned {
fn drop(&mut self) {
for &object in &self.0 {
unsafe { dec(object) }
}
}
}
struct Rest(std::vec::IntoIter<Obj>);
impl Drop for Rest {
fn drop(&mut self) {
for object in &mut self.0 {
unsafe { dec(object) }
}
}
}
pub struct Fields {
object: Obj,
exclusive: bool,
}
impl Fields {
#[inline(always)]
pub unsafe fn of(object: Obj) -> Fields {
Fields { object, exclusive: o::is_exclusive(object) }
}
#[inline(always)]
pub unsafe fn object<C: Codec>(&self, i: u32) -> Value<C> {
let field = o::ctor_get(self.object, i);
if self.exclusive {
Value::take(field)
} else {
Value::share(field)
}
}
#[inline(always)]
pub unsafe fn done(self) {
if self.exclusive {
o::free_object(self.object)
} else {
dec_ref(self.object)
}
}
}
pub struct Array<C>(PhantomData<C>);
impl<C: Codec> Array<C> {
pub fn from_values(items: impl ExactSizeIterator<Item = Value<C>>) -> Value<Self> {
let mut objects = Owned(Vec::with_capacity(items.len()));
for item in items {
objects.0.push(item.into_object());
}
unsafe { Value::from_raw(crate::array::from_vec(objects.into_vec())) }
}
}
impl<C: Codec> Codec for Array<C> {
type Rust = Vec<C::Rust>;
type Repr = Obj;
fn into_lean(value: Vec<C::Rust>) -> Value<Self> {
Self::from_values(value.into_iter().map(C::into_lean))
}
fn to_lean(value: &Vec<C::Rust>) -> Value<Self> {
Self::from_values(value.iter().map(C::to_lean))
}
fn from_lean(value: Value<Self>) -> Vec<C::Rust> {
let object = value.into_raw();
unsafe {
if o::is_exclusive(object) {
let mut rest = Rest(crate::array::into_vec(object).into_iter());
let mut items = Vec::with_capacity(rest.0.len());
while let Some(item) = rest.0.next() {
items.push(C::from_lean(Value::take(item)));
}
items
} else {
let _shared = Value::<Self>::from_raw(object);
crate::array::elements(object).iter().map(|&item| C::from_lean(Value::share(item))).collect()
}
}
}
}
pub struct List<C>(PhantomData<C>);
impl<C: Codec> List<C> {
fn build(items: impl Iterator<Item = Obj>) -> Value<Self> {
let mut list: Value<Self> = unsafe { Value::from_raw(box_(0)) };
for item in items {
unsafe {
let cell = o::alloc_ctor(1, 2, 0, 0);
o::ctor_set(cell, 0, item);
o::ctor_set(cell, 1, list.into_raw());
list = Value::from_raw(cell);
}
}
list
}
}
impl<C: Codec> Codec for List<C> {
type Rust = Vec<C::Rust>;
type Repr = Obj;
fn into_lean(value: Vec<C::Rust>) -> Value<Self> {
Self::build(value.into_iter().rev().map(|item| C::into_lean(item).into_object()))
}
fn to_lean(value: &Vec<C::Rust>) -> Value<Self> {
Self::build(value.iter().rev().map(|item| C::to_lean(item).into_object()))
}
fn from_lean(value: Value<Self>) -> Vec<C::Rust> {
let mut items = Vec::new();
let mut rest = value;
loop {
let cell = rest.into_raw();
if o::is_scalar(cell) {
return items;
}
unsafe {
let fields = Fields::of(cell);
let head = fields.object::<C>(0);
let tail = fields.object::<Self>(1);
fields.done();
rest = tail;
items.push(C::from_lean(head));
}
}
}
}
pub struct Option<C>(PhantomData<C>);
impl<C: Codec> Option<C> {
fn some(field: Value<C>) -> Value<Self> {
unsafe {
let some = o::alloc_ctor(1, 1, 0, 0);
o::ctor_set(some, 0, field.into_object());
Value::from_raw(some)
}
}
}
impl<C: Codec> Codec for Option<C> {
type Rust = core::option::Option<C::Rust>;
type Repr = Obj;
fn into_lean(value: Self::Rust) -> Value<Self> {
match value {
None => unsafe { Value::from_raw(box_(0)) },
Some(value) => Self::some(C::into_lean(value)),
}
}
fn to_lean(value: &Self::Rust) -> Value<Self> {
match value {
None => unsafe { Value::from_raw(box_(0)) },
Some(value) => Self::some(C::to_lean(value)),
}
}
fn from_lean(value: Value<Self>) -> Self::Rust {
let object = value.into_raw();
if o::is_scalar(object) {
return None;
}
unsafe {
let fields = Fields::of(object);
let field = fields.object::<C>(0);
fields.done();
Some(C::from_lean(field))
}
}
}
pub struct Prod<A, B>(PhantomData<(A, B)>);
impl<A: Codec, B: Codec> Prod<A, B> {
fn pair(first: Value<A>, second: Value<B>) -> Value<Self> {
unsafe {
let pair = o::alloc_ctor(0, 2, 0, 0);
o::ctor_set(pair, 0, first.into_object());
o::ctor_set(pair, 1, second.into_object());
Value::from_raw(pair)
}
}
pub fn from_refs(first: &A::Rust, second: &B::Rust) -> Value<Self> {
Self::pair(A::to_lean(first), B::to_lean(second))
}
}
impl<A: Codec, B: Codec> Codec for Prod<A, B> {
type Rust = (A::Rust, B::Rust);
type Repr = Obj;
fn into_lean(value: Self::Rust) -> Value<Self> {
let first = A::into_lean(value.0);
Self::pair(first, B::into_lean(value.1))
}
fn to_lean(value: &Self::Rust) -> Value<Self> {
Self::from_refs(&value.0, &value.1)
}
fn from_lean(value: Value<Self>) -> Self::Rust {
unsafe {
let fields = Fields::of(value.into_raw());
let (first, second) = (fields.object::<A>(0), fields.object::<B>(1));
fields.done();
let first = A::from_lean(first);
(first, B::from_lean(second))
}
}
}
pub struct Except<E, A>(PhantomData<(E, A)>);
impl<E: Codec, A: Codec> Except<E, A> {
fn with(tag: u32, field: Obj) -> Value<Self> {
unsafe {
let object = o::alloc_ctor(tag, 1, 0, 0);
o::ctor_set(object, 0, field);
Value::from_raw(object)
}
}
}
impl<E: Codec, A: Codec> Codec for Except<E, A> {
type Rust = Result<A::Rust, E::Rust>;
type Repr = Obj;
fn into_lean(value: Self::Rust) -> Value<Self> {
match value {
Err(error) => Self::with(0, E::into_lean(error).into_object()),
Ok(value) => Self::with(1, A::into_lean(value).into_object()),
}
}
fn to_lean(value: &Self::Rust) -> Value<Self> {
match value {
Err(error) => Self::with(0, E::to_lean(error).into_object()),
Ok(value) => Self::with(1, A::to_lean(value).into_object()),
}
}
fn from_lean(value: Value<Self>) -> Self::Rust {
let object = value.into_raw();
unsafe {
let ok = o::obj_tag(object) == 1;
let fields = Fields::of(object);
if ok {
let field = fields.object::<A>(0);
fields.done();
Ok(A::from_lean(field))
} else {
let field = fields.object::<E>(0);
fields.done();
Err(E::from_lean(field))
}
}
}
}
pub struct Boxed<C>(PhantomData<C>);
impl<C: Codec> Codec for Boxed<C> {
type Rust = Box<C::Rust>;
type Repr = C::Repr;
fn into_lean(value: Self::Rust) -> Value<Self> {
unsafe { C::into_lean(*value).cast() }
}
fn to_lean(value: &Self::Rust) -> Value<Self> {
unsafe { C::to_lean(value).cast() }
}
fn from_lean(value: Value<Self>) -> Self::Rust {
Box::new(C::from_lean(unsafe { value.cast() }))
}
}
pub struct Opaque<T>(PhantomData<T>);
impl<T: Clone + 'static> Codec for Opaque<T> {
type Rust = T;
type Repr = Obj;
fn into_lean(value: T) -> Value<Self> {
unsafe { Value::from_raw(o::hold_external(value)) }
}
fn to_lean(value: &T) -> Value<Self> {
Self::into_lean(value.clone())
}
unsafe fn lent(value: &T) -> Value<Self> {
Value::from_raw(o::lend_external(value))
}
fn from_lean(value: Value<Self>) -> T {
unsafe {
if o::is_exclusive(value.as_raw()) && !o::is_lent(value.as_raw()) {
o::take_external(value.into_raw())
} else {
o::external::<T>(value.as_raw()).clone()
}
}
}
fn lend<R>(value: &Value<Self>, f: impl FnOnce(&T) -> R) -> R {
f(unsafe { o::external::<T>(value.as_raw()) })
}
}
pub(crate) fn fixed_limbs<const N: usize>(limbs: &[u64]) -> core::option::Option<[u64; N]> {
let mut out = [0u64; N];
out.get_mut(..limbs.len())?.copy_from_slice(limbs);
Some(out)
}
pub trait Word: Copy {
#[doc(hidden)]
fn to_nat(self) -> Obj;
#[doc(hidden)]
unsafe fn of_nat(nat: Obj) -> Self;
}
macro_rules! words {
($($ty:ty),*) => {$(
impl Word for $ty {
fn to_nat(self) -> Obj {
crate::nat::uint64_to_nat(self as u64)
}
unsafe fn of_nat(nat: Obj) -> $ty {
crate::nat::with_limbs(nat, |limbs| limbs.first().copied().unwrap_or(0)) as $ty
}
}
)*};
}
words!(u8, u16, u32, u64);
impl Word for u128 {
fn to_nat(self) -> Obj {
crate::nat::of_u128(self)
}
unsafe fn of_nat(nat: Obj) -> u128 {
let [low, high] = <[u64; 2]>::of_nat(nat);
(high as u128) << 64 | low as u128
}
}
impl<const N: usize> Word for [u64; N] {
fn to_nat(self) -> Obj {
crate::nat::of_limbs(&self)
}
unsafe fn of_nat(nat: Obj) -> [u64; N] {
match crate::nat::with_limbs(nat, fixed_limbs) {
Some(limbs) => limbs,
None => panic!("inlean: Lean returned a BitVec wider than its type"),
}
}
}
pub struct BitVec<W>(PhantomData<W>);
impl<W: Word> Codec for BitVec<W> {
type Rust = W;
type Repr = Obj;
fn into_lean(value: W) -> Value<Self> {
unsafe { Value::from_raw(value.to_nat()) }
}
fn to_lean(value: &W) -> Value<Self> {
Self::into_lean(*value)
}
fn from_lean(value: Value<Self>) -> W {
unsafe { W::of_nat(value.as_raw()) }
}
}
pub trait Primitive {
type Lean;
type Rust;
fn to_lean(value: &Self::Rust) -> Self::Lean;
fn into_lean(value: Self::Rust) -> Self::Lean {
Self::to_lean(&value)
}
fn from_lean(value: Self::Lean) -> Self::Rust;
}
pub struct Via<C, P>(PhantomData<(C, P)>);
impl<C: Codec, P: Primitive<Lean = C::Rust>> Codec for Via<C, P> {
type Rust = P::Rust;
type Repr = C::Repr;
fn into_lean(value: P::Rust) -> Value<Self> {
unsafe { C::into_lean(P::into_lean(value)).cast() }
}
fn to_lean(value: &P::Rust) -> Value<Self> {
unsafe { C::into_lean(P::to_lean(value)).cast() }
}
fn from_lean(value: Value<Self>) -> P::Rust {
P::from_lean(C::from_lean(unsafe { value.cast() }))
}
}
pub trait Pass<T>: Sized {
#[doc(hidden)]
fn pass<C: Codec<Rust = T>>(self) -> Value<C>;
#[doc(hidden)]
#[inline]
unsafe fn lend<C: Codec<Rust = T>>(self) -> Value<C> {
self.pass()
}
}
impl<T> Pass<T> for T {
#[inline]
fn pass<C: Codec<Rust = T>>(self) -> Value<C> {
C::into_lean(self)
}
}
impl<T> Pass<T> for &T {
#[inline]
fn pass<C: Codec<Rust = T>>(self) -> Value<C> {
C::to_lean(self)
}
#[inline]
unsafe fn lend<C: Codec<Rust = T>>(self) -> Value<C> {
C::lent(self)
}
}
impl Pass<std::string::String> for &str {
#[inline]
fn pass<C: Codec<Rust = std::string::String>>(self) -> Value<C> {
C::into_lean(self.to_owned())
}
}
impl<T: Clone> Pass<Vec<T>> for &[T] {
#[inline]
fn pass<C: Codec<Rust = Vec<T>>>(self) -> Value<C> {
C::into_lean(self.to_vec())
}
}
impl<T: Clone, const N: usize> Pass<Vec<T>> for &[T; N] {
#[inline]
fn pass<C: Codec<Rust = Vec<T>>>(self) -> Value<C> {
C::into_lean(self.to_vec())
}
}
impl<T, const N: usize> Pass<Vec<T>> for [T; N] {
#[inline]
fn pass<C: Codec<Rust = Vec<T>>>(self) -> Value<C> {
C::into_lean(Vec::from(self))
}
}
impl<T> Pass<T> for Box<T> {
#[inline]
fn pass<C: Codec<Rust = T>>(self) -> Value<C> {
C::into_lean(*self)
}
}
impl<T> Pass<T> for &Box<T> {
#[inline]
fn pass<C: Codec<Rust = T>>(self) -> Value<C> {
C::to_lean(self)
}
#[inline]
unsafe fn lend<C: Codec<Rust = T>>(self) -> Value<C> {
C::lent(self)
}
}
impl<T> Pass<T> for &std::rc::Rc<T> {
#[inline]
fn pass<C: Codec<Rust = T>>(self) -> Value<C> {
C::to_lean(self)
}
#[inline]
unsafe fn lend<C: Codec<Rust = T>>(self) -> Value<C> {
C::lent(self)
}
}
impl<T> Pass<T> for &std::sync::Arc<T> {
#[inline]
fn pass<C: Codec<Rust = T>>(self) -> Value<C> {
C::to_lean(self)
}
#[inline]
unsafe fn lend<C: Codec<Rust = T>>(self) -> Value<C> {
C::lent(self)
}
}
impl<T: Clone> Pass<T> for std::borrow::Cow<'_, T> {
#[inline]
fn pass<C: Codec<Rust = T>>(self) -> Value<C> {
C::into_lean(self.into_owned())
}
}
impl Pass<std::string::String> for std::borrow::Cow<'_, str> {
#[inline]
fn pass<C: Codec<Rust = std::string::String>>(self) -> Value<C> {
C::into_lean(self.into_owned())
}
}
impl<T: Clone> Pass<Vec<T>> for std::borrow::Cow<'_, [T]> {
#[inline]
fn pass<C: Codec<Rust = Vec<T>>>(self) -> Value<C> {
C::into_lean(self.into_owned())
}
}