pub trait TryFromRoot<'a>: Sized {
type Error;
#[doc(hidden)] const NATIVE_BORROW: Option<NativeBorrow> = None;
// Required method
fn try_from_root(root: Root<'a>) -> Result<Self, Self::Error>;
}Expand description
Convert an R value while retaining its root’s lifetime in the result.
This conversion carries the root lifetime that raw TryFromSexp
cannot express.
Generated wrappers use the rooted .Call argument for StrVec, RCow,
and Cow inputs (including the character-vector Cow containers). Main-thread
wrappers and trait shims also use it for explicit shared native references
and optional shared references. Worker shared references copy to Rust-owned
scalars, vectors or strings before dispatch, then borrow inside the worker.
Nested shared-reference Vec inputs retain every list element in the root’s
protection scope, even when an ALTREP accessor does not cache that element.
A type alias can use this trait explicitly in the function body.
A root proves liveness, not exclusive access: this trait does not provide mutable references to R storage. Shared native borrows still participate in a wrapper’s alias checks against its other, mutable arguments.
use miniextendr_api::{Root, TryFromRoot};
use std::borrow::Cow;
fn escape<'a>(root: Root<'a>) -> Cow<'static, [i32]> {
Cow::try_from_root(root).unwrap()
}use miniextendr_api::{Root, TryFromRoot};
use std::borrow::Cow;
fn escape<'a>(root: Root<'a>) -> Vec<Option<Cow<'static, str>>> {
Vec::try_from_root(root).unwrap()
}use miniextendr_api::{Root, TryFromRoot};
fn escape<'a>(root: Root<'a>) -> &'static [i32] {
<&[i32]>::try_from_root(root).unwrap()
}use miniextendr_api::{Root, TryFromRoot};
fn escape<'a>(root: Root<'a>) -> Option<&'static str> {
<Option<&str>>::try_from_root(root).unwrap()
}use miniextendr_api::{Root, TryFromRoot};
fn escape<'a>(root: Root<'a>) -> Vec<Vec<&'static [i32]>> {
Vec::try_from_root(root).unwrap()
}Provided Associated Constants§
Source#[doc(hidden)]const NATIVE_BORROW: Option<NativeBorrow> = None
#[doc(hidden)]const NATIVE_BORROW: Option<NativeBorrow> = None
Native storage borrowed by this conversion, for wrapper alias checks.
Required Associated Types§
Required Methods§
Sourcefn try_from_root(root: Root<'a>) -> Result<Self, Self::Error>
fn try_from_root(root: Root<'a>) -> Result<Self, Self::Error>
Convert without allowing an R-backed borrow to outlive root.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<'a, E: RootedVecElement<'a>> TryFromRoot<'a> for Option<Vec<E>>
NULL is None; anything else converts as the Vec.
impl<'a, E: RootedVecElement<'a>> TryFromRoot<'a> for Option<Vec<E>>
NULL is None; anything else converts as the Vec.
const NATIVE_BORROW: Option<NativeBorrow> = E::NATIVE_BORROW
type Error = SexpError
fn try_from_root(root: Root<'a>) -> Result<Self, Self::Error>
Source§impl<'a, E: RootedVecElement<'a>> TryFromRoot<'a> for Vec<E>
impl<'a, E: RootedVecElement<'a>> TryFromRoot<'a> for Vec<E>
const NATIVE_BORROW: Option<NativeBorrow> = E::NATIVE_BORROW
type Error = SexpError
fn try_from_root(root: Root<'a>) -> Result<Self, Self::Error>
Source§impl<'a, T: ?Sized + 'static> TryFromRoot<'a> for &'a Twhere
&'static T: TryFromSexp,
A shared reference converts as its raw 'static form does, with the same
checks, errors and alias metadata, and so does a custom TryFromSexp impl
for a reference to the user’s own type. Only the lifetime changes: the
result borrows from the root, not from 'static.
impl<'a, T: ?Sized + 'static> TryFromRoot<'a> for &'a Twhere
&'static T: TryFromSexp,
A shared reference converts as its raw 'static form does, with the same
checks, errors and alias metadata, and so does a custom TryFromSexp impl
for a reference to the user’s own type. Only the lifetime changes: the
result borrows from the root, not from 'static.
const NATIVE_BORROW: Option<NativeBorrow> = <&'static T as TryFromSexp>::NATIVE_BORROW
type Error = <&'static T as TryFromSexp>::Error
fn try_from_root(root: Root<'a>) -> Result<Self, Self::Error>
Source§impl<'a, T: ?Sized + 'static> TryFromRoot<'a> for Option<&'a T>
NULL (and NA for strings) is None, as in the raw conversion.
impl<'a, T: ?Sized + 'static> TryFromRoot<'a> for Option<&'a T>
NULL (and NA for strings) is None, as in the raw conversion.