miniextendr_api/trait_abi/
signature.rs1use crate::from_r::NativeBorrow;
9use crate::from_r::prepared::Prepared;
10use crate::gc_protect::Root;
11use crate::{SEXP, TryFromRoot, TryFromSexp};
12use core::marker::PhantomData;
13
14#[doc(hidden)]
16pub struct Argument<T>(PhantomData<fn() -> T>);
17
18impl<T> Argument<T> {
19 pub const NEW: Self = Self(PhantomData);
21
22 pub fn convert(&self, input: SEXP) -> Result<T, T::Error>
24 where
25 T: TryFromSexp,
26 {
27 T::try_from_sexp(input)
28 }
29
30 pub fn prepare(&self, input: SEXP) -> Prepared<T>
33 where
34 T: TryFromSexp,
35 {
36 T::__mx_prepare(input)
37 }
38
39 pub fn convert_prepared(&self, prepared: Prepared<T>, input: SEXP) -> Result<T, T::Error>
41 where
42 T: TryFromSexp,
43 {
44 crate::from_r::prepared::convert(prepared, input)
45 }
46
47 pub fn rooted<'a>(&self, input: Root<'a>) -> Result<T, T::Error>
49 where
50 T: TryFromRoot<'a>,
51 {
52 T::try_from_root(input)
53 }
54
55 pub fn native_borrow(&self) -> Option<NativeBorrow>
57 where
58 T: TryFromSexp,
59 {
60 T::NATIVE_BORROW
61 }
62
63 pub fn rooted_native_borrow<'a>(&self) -> Option<NativeBorrow>
65 where
66 T: TryFromRoot<'a>,
67 {
68 T::NATIVE_BORROW
69 }
70
71 pub fn expectation(&self) -> Option<&'static str>
73 where
74 T: TryFromSexp,
75 {
76 T::__MX_EXPECTATION
77 }
78}