Skip to main content

miniextendr_api/
wrap_as.rs

1//! Explicit R class-system return markers.
2//!
3//! `WrapAsR6<T>` and its siblings select the constructor used by the generated
4//! R wrapper. The matching attribute is `#[miniextendr(wrap = "r6")]`.
5//! Both forms leave Rust-to-R value conversion to `T`; they only select the
6//! R-side wrapping expression. See `docs/MINIEXTENDR_ATTRIBUTE.md` for examples.
7//!
8//! `ConvertTo<T>` and `ConvertFrom<T>` additionally register an inherent S7
9//! method with `S7::convert`. `ConvertTo<T>` names the target payload;
10//! `ConvertFrom<Self>` infers the source from its static method's sole typed
11//! parameter. Both use the existing S7 class-name resolver, including registered
12//! R class renames, and have matching `s7(convert_to = "Target")` /
13//! `s7(convert_from = "Source")` attributes.
14//!
15//! Markers are recognized by their last path segment. Type aliases and renamed
16//! imports do not select wrapping. Put `Invisible`/`Visible` outside the whole
17//! return, and `Option`, `Result`, or `Vec` outside the class marker.
18//!
19//! The marker selects the class system; the class name is the R name the
20//! target's `#[miniextendr]` impl block registers, resolved when the R wrappers
21//! are written, so a `class = "..."` rename applies (`Self` is the implementing
22//! class). A target with no impl block keeps its Rust name: quietly for S3, Env
23//! and vctrs, where any string is a class, and with a warning for R6, S7 and S4,
24//! whose class object must exist. Nothing checks that the selected system
25//! matches the class definition; a mismatch is reported by R when the
26//! generated constructor or method is used.
27
28use crate::IntoR;
29
30macro_rules! wrap_marker {
31    ($name:ident, $docs:literal) => {
32        #[doc = $docs]
33        #[repr(transparent)]
34        #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
35        pub struct $name<T>(pub T);
36
37        impl<T> $name<T> {
38            /// Wrap a value for an explicit R return class.
39            pub const fn new(value: T) -> Self {
40                Self(value)
41            }
42            /// Recover the Rust value.
43            pub fn into_inner(self) -> T {
44                self.0
45            }
46        }
47
48        impl<T> From<T> for $name<T> {
49            fn from(value: T) -> Self {
50                Self(value)
51            }
52        }
53
54        impl<T> std::ops::Deref for $name<T> {
55            type Target = T;
56            fn deref(&self) -> &T {
57                &self.0
58            }
59        }
60
61        impl<T> std::ops::DerefMut for $name<T> {
62            fn deref_mut(&mut self) -> &mut T {
63                &mut self.0
64            }
65        }
66
67        impl<T: IntoR> IntoR for $name<T> {
68            type Error = T::Error;
69            fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
70                self.0.try_into_sexp()
71            }
72            unsafe fn try_into_sexp_unchecked(self) -> Result<crate::SEXP, Self::Error> {
73                // SAFETY: the caller provides T's ordinary conversion guarantees.
74                unsafe { self.0.try_into_sexp_unchecked() }
75            }
76        }
77    };
78}
79
80#[doc = "Return `T` through its R6 constructor (`T$new(.ptr = value)`)."]
#[repr(transparent)]
pub struct WrapAsR6<T>(pub T);
#[automatically_derived]impl<T: ::core::fmt::Debug> ::core::fmt::Debug for
    WrapAsR6<T> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f, "WrapAsR6",
            &&self.0)
    }
}
#[automatically_derived]impl<T: ::core::clone::Clone> ::core::clone::Clone for
    WrapAsR6<T> {
    #[inline]
    fn clone(&self) -> Self { WrapAsR6(::core::clone::Clone::clone(&self.0)) }
}
#[automatically_derived]impl<T: ::core::marker::Copy> ::core::marker::Copy for
    WrapAsR6<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq>
    ::core::marker::StructuralPartialEq for WrapAsR6<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq
    for WrapAsR6<T> {
    #[inline]
    fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]impl<T: ::core::cmp::Eq> ::core::cmp::Eq for
    WrapAsR6<T> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) { let _: ::core::cmp::AssertParamIsEq<T>; }
}
#[automatically_derived]impl<T: ::core::cmp::PartialOrd>
    ::core::cmp::PartialOrd for WrapAsR6<T> {
    #[inline]
    fn partial_cmp(&self, other: &Self)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::cmp::Ord> ::core::cmp::Ord for
    WrapAsR6<T> {
    #[inline]
    fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
        ::core::cmp::Ord::cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::hash::Hash> ::core::hash::Hash for
    WrapAsR6<T> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.0, state)
    }
}
#[automatically_derived]impl<T: ::core::default::Default>
    ::core::default::Default for WrapAsR6<T> {
    #[inline]
    fn default() -> Self { WrapAsR6(::core::default::Default::default()) }
}
impl<T> WrapAsR6<T> {
    /// Wrap a value for an explicit R return class.
    pub const fn new(value: T) -> Self { Self(value) }
    /// Recover the Rust value.
    pub fn into_inner(self) -> T { self.0 }
}
impl<T> From<T> for WrapAsR6<T> {
    fn from(value: T) -> Self { Self(value) }
}
impl<T> std::ops::Deref for WrapAsR6<T> {
    type Target = T;
    fn deref(&self) -> &T { &self.0 }
}
impl<T> std::ops::DerefMut for WrapAsR6<T> {
    fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T: IntoR> IntoR for WrapAsR6<T> {
    type Error = T::Error;
    fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
        self.0.try_into_sexp()
    }
    unsafe fn try_into_sexp_unchecked(self)
        -> Result<crate::SEXP, Self::Error> {
        unsafe { self.0.try_into_sexp_unchecked() }
    }
}wrap_marker!(
81    WrapAsR6,
82    "Return `T` through its R6 constructor (`T$new(.ptr = value)`)."
83);
84#[doc = "Return `T` through its S7 constructor (`T(.ptr = value)`)."]
#[repr(transparent)]
pub struct WrapAsS7<T>(pub T);
#[automatically_derived]impl<T: ::core::fmt::Debug> ::core::fmt::Debug for
    WrapAsS7<T> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f, "WrapAsS7",
            &&self.0)
    }
}
#[automatically_derived]impl<T: ::core::clone::Clone> ::core::clone::Clone for
    WrapAsS7<T> {
    #[inline]
    fn clone(&self) -> Self { WrapAsS7(::core::clone::Clone::clone(&self.0)) }
}
#[automatically_derived]impl<T: ::core::marker::Copy> ::core::marker::Copy for
    WrapAsS7<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq>
    ::core::marker::StructuralPartialEq for WrapAsS7<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq
    for WrapAsS7<T> {
    #[inline]
    fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]impl<T: ::core::cmp::Eq> ::core::cmp::Eq for
    WrapAsS7<T> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) { let _: ::core::cmp::AssertParamIsEq<T>; }
}
#[automatically_derived]impl<T: ::core::cmp::PartialOrd>
    ::core::cmp::PartialOrd for WrapAsS7<T> {
    #[inline]
    fn partial_cmp(&self, other: &Self)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::cmp::Ord> ::core::cmp::Ord for
    WrapAsS7<T> {
    #[inline]
    fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
        ::core::cmp::Ord::cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::hash::Hash> ::core::hash::Hash for
    WrapAsS7<T> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.0, state)
    }
}
#[automatically_derived]impl<T: ::core::default::Default>
    ::core::default::Default for WrapAsS7<T> {
    #[inline]
    fn default() -> Self { WrapAsS7(::core::default::Default::default()) }
}
impl<T> WrapAsS7<T> {
    /// Wrap a value for an explicit R return class.
    pub const fn new(value: T) -> Self { Self(value) }
    /// Recover the Rust value.
    pub fn into_inner(self) -> T { self.0 }
}
impl<T> From<T> for WrapAsS7<T> {
    fn from(value: T) -> Self { Self(value) }
}
impl<T> std::ops::Deref for WrapAsS7<T> {
    type Target = T;
    fn deref(&self) -> &T { &self.0 }
}
impl<T> std::ops::DerefMut for WrapAsS7<T> {
    fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T: IntoR> IntoR for WrapAsS7<T> {
    type Error = T::Error;
    fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
        self.0.try_into_sexp()
    }
    unsafe fn try_into_sexp_unchecked(self)
        -> Result<crate::SEXP, Self::Error> {
        unsafe { self.0.try_into_sexp_unchecked() }
    }
}wrap_marker!(
85    WrapAsS7,
86    "Return `T` through its S7 constructor (`T(.ptr = value)`)."
87);
88#[doc = "Return `T` through `methods::new(\"T\", ptr = value)`."]
#[repr(transparent)]
pub struct WrapAsS4<T>(pub T);
#[automatically_derived]impl<T: ::core::fmt::Debug> ::core::fmt::Debug for
    WrapAsS4<T> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f, "WrapAsS4",
            &&self.0)
    }
}
#[automatically_derived]impl<T: ::core::clone::Clone> ::core::clone::Clone for
    WrapAsS4<T> {
    #[inline]
    fn clone(&self) -> Self { WrapAsS4(::core::clone::Clone::clone(&self.0)) }
}
#[automatically_derived]impl<T: ::core::marker::Copy> ::core::marker::Copy for
    WrapAsS4<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq>
    ::core::marker::StructuralPartialEq for WrapAsS4<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq
    for WrapAsS4<T> {
    #[inline]
    fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]impl<T: ::core::cmp::Eq> ::core::cmp::Eq for
    WrapAsS4<T> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) { let _: ::core::cmp::AssertParamIsEq<T>; }
}
#[automatically_derived]impl<T: ::core::cmp::PartialOrd>
    ::core::cmp::PartialOrd for WrapAsS4<T> {
    #[inline]
    fn partial_cmp(&self, other: &Self)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::cmp::Ord> ::core::cmp::Ord for
    WrapAsS4<T> {
    #[inline]
    fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
        ::core::cmp::Ord::cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::hash::Hash> ::core::hash::Hash for
    WrapAsS4<T> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.0, state)
    }
}
#[automatically_derived]impl<T: ::core::default::Default>
    ::core::default::Default for WrapAsS4<T> {
    #[inline]
    fn default() -> Self { WrapAsS4(::core::default::Default::default()) }
}
impl<T> WrapAsS4<T> {
    /// Wrap a value for an explicit R return class.
    pub const fn new(value: T) -> Self { Self(value) }
    /// Recover the Rust value.
    pub fn into_inner(self) -> T { self.0 }
}
impl<T> From<T> for WrapAsS4<T> {
    fn from(value: T) -> Self { Self(value) }
}
impl<T> std::ops::Deref for WrapAsS4<T> {
    type Target = T;
    fn deref(&self) -> &T { &self.0 }
}
impl<T> std::ops::DerefMut for WrapAsS4<T> {
    fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T: IntoR> IntoR for WrapAsS4<T> {
    type Error = T::Error;
    fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
        self.0.try_into_sexp()
    }
    unsafe fn try_into_sexp_unchecked(self)
        -> Result<crate::SEXP, Self::Error> {
        unsafe { self.0.try_into_sexp_unchecked() }
    }
}wrap_marker!(
89    WrapAsS4,
90    "Return `T` through `methods::new(\"T\", ptr = value)`."
91);
92#[doc = "Return `T` with its named S3 class."]
#[repr(transparent)]
pub struct WrapAsS3<T>(pub T);
#[automatically_derived]impl<T: ::core::fmt::Debug> ::core::fmt::Debug for
    WrapAsS3<T> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f, "WrapAsS3",
            &&self.0)
    }
}
#[automatically_derived]impl<T: ::core::clone::Clone> ::core::clone::Clone for
    WrapAsS3<T> {
    #[inline]
    fn clone(&self) -> Self { WrapAsS3(::core::clone::Clone::clone(&self.0)) }
}
#[automatically_derived]impl<T: ::core::marker::Copy> ::core::marker::Copy for
    WrapAsS3<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq>
    ::core::marker::StructuralPartialEq for WrapAsS3<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq
    for WrapAsS3<T> {
    #[inline]
    fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]impl<T: ::core::cmp::Eq> ::core::cmp::Eq for
    WrapAsS3<T> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) { let _: ::core::cmp::AssertParamIsEq<T>; }
}
#[automatically_derived]impl<T: ::core::cmp::PartialOrd>
    ::core::cmp::PartialOrd for WrapAsS3<T> {
    #[inline]
    fn partial_cmp(&self, other: &Self)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::cmp::Ord> ::core::cmp::Ord for
    WrapAsS3<T> {
    #[inline]
    fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
        ::core::cmp::Ord::cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::hash::Hash> ::core::hash::Hash for
    WrapAsS3<T> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.0, state)
    }
}
#[automatically_derived]impl<T: ::core::default::Default>
    ::core::default::Default for WrapAsS3<T> {
    #[inline]
    fn default() -> Self { WrapAsS3(::core::default::Default::default()) }
}
impl<T> WrapAsS3<T> {
    /// Wrap a value for an explicit R return class.
    pub const fn new(value: T) -> Self { Self(value) }
    /// Recover the Rust value.
    pub fn into_inner(self) -> T { self.0 }
}
impl<T> From<T> for WrapAsS3<T> {
    fn from(value: T) -> Self { Self(value) }
}
impl<T> std::ops::Deref for WrapAsS3<T> {
    type Target = T;
    fn deref(&self) -> &T { &self.0 }
}
impl<T> std::ops::DerefMut for WrapAsS3<T> {
    fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T: IntoR> IntoR for WrapAsS3<T> {
    type Error = T::Error;
    fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
        self.0.try_into_sexp()
    }
    unsafe fn try_into_sexp_unchecked(self)
        -> Result<crate::SEXP, Self::Error> {
        unsafe { self.0.try_into_sexp_unchecked() }
    }
}wrap_marker!(WrapAsS3, "Return `T` with its named S3 class.");
93#[doc = "Return `T` with its Env dispatch class."]
#[repr(transparent)]
pub struct WrapAsEnv<T>(pub T);
#[automatically_derived]impl<T: ::core::fmt::Debug> ::core::fmt::Debug for
    WrapAsEnv<T> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f, "WrapAsEnv",
            &&self.0)
    }
}
#[automatically_derived]impl<T: ::core::clone::Clone> ::core::clone::Clone for
    WrapAsEnv<T> {
    #[inline]
    fn clone(&self) -> Self {
        WrapAsEnv(::core::clone::Clone::clone(&self.0))
    }
}
#[automatically_derived]impl<T: ::core::marker::Copy> ::core::marker::Copy for
    WrapAsEnv<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq>
    ::core::marker::StructuralPartialEq for WrapAsEnv<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq
    for WrapAsEnv<T> {
    #[inline]
    fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]impl<T: ::core::cmp::Eq> ::core::cmp::Eq for
    WrapAsEnv<T> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) { let _: ::core::cmp::AssertParamIsEq<T>; }
}
#[automatically_derived]impl<T: ::core::cmp::PartialOrd>
    ::core::cmp::PartialOrd for WrapAsEnv<T> {
    #[inline]
    fn partial_cmp(&self, other: &Self)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::cmp::Ord> ::core::cmp::Ord for
    WrapAsEnv<T> {
    #[inline]
    fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
        ::core::cmp::Ord::cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::hash::Hash> ::core::hash::Hash for
    WrapAsEnv<T> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.0, state)
    }
}
#[automatically_derived]impl<T: ::core::default::Default>
    ::core::default::Default for WrapAsEnv<T> {
    #[inline]
    fn default() -> Self { WrapAsEnv(::core::default::Default::default()) }
}
impl<T> WrapAsEnv<T> {
    /// Wrap a value for an explicit R return class.
    pub const fn new(value: T) -> Self { Self(value) }
    /// Recover the Rust value.
    pub fn into_inner(self) -> T { self.0 }
}
impl<T> From<T> for WrapAsEnv<T> {
    fn from(value: T) -> Self { Self(value) }
}
impl<T> std::ops::Deref for WrapAsEnv<T> {
    type Target = T;
    fn deref(&self) -> &T { &self.0 }
}
impl<T> std::ops::DerefMut for WrapAsEnv<T> {
    fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T: IntoR> IntoR for WrapAsEnv<T> {
    type Error = T::Error;
    fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
        self.0.try_into_sexp()
    }
    unsafe fn try_into_sexp_unchecked(self)
        -> Result<crate::SEXP, Self::Error> {
        unsafe { self.0.try_into_sexp_unchecked() }
    }
}wrap_marker!(WrapAsEnv, "Return `T` with its Env dispatch class.");
94#[doc =
"Return `T` with its named vctrs class, preserving its existing class hierarchy."]
#[repr(transparent)]
pub struct WrapAsVctrs<T>(pub T);
#[automatically_derived]impl<T: ::core::fmt::Debug> ::core::fmt::Debug for
    WrapAsVctrs<T> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f, "WrapAsVctrs",
            &&self.0)
    }
}
#[automatically_derived]impl<T: ::core::clone::Clone> ::core::clone::Clone for
    WrapAsVctrs<T> {
    #[inline]
    fn clone(&self) -> Self {
        WrapAsVctrs(::core::clone::Clone::clone(&self.0))
    }
}
#[automatically_derived]impl<T: ::core::marker::Copy> ::core::marker::Copy for
    WrapAsVctrs<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq>
    ::core::marker::StructuralPartialEq for WrapAsVctrs<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq
    for WrapAsVctrs<T> {
    #[inline]
    fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]impl<T: ::core::cmp::Eq> ::core::cmp::Eq for
    WrapAsVctrs<T> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) { let _: ::core::cmp::AssertParamIsEq<T>; }
}
#[automatically_derived]impl<T: ::core::cmp::PartialOrd>
    ::core::cmp::PartialOrd for WrapAsVctrs<T> {
    #[inline]
    fn partial_cmp(&self, other: &Self)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::cmp::Ord> ::core::cmp::Ord for
    WrapAsVctrs<T> {
    #[inline]
    fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
        ::core::cmp::Ord::cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::hash::Hash> ::core::hash::Hash for
    WrapAsVctrs<T> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.0, state)
    }
}
#[automatically_derived]impl<T: ::core::default::Default>
    ::core::default::Default for WrapAsVctrs<T> {
    #[inline]
    fn default() -> Self { WrapAsVctrs(::core::default::Default::default()) }
}
impl<T> WrapAsVctrs<T> {
    /// Wrap a value for an explicit R return class.
    pub const fn new(value: T) -> Self { Self(value) }
    /// Recover the Rust value.
    pub fn into_inner(self) -> T { self.0 }
}
impl<T> From<T> for WrapAsVctrs<T> {
    fn from(value: T) -> Self { Self(value) }
}
impl<T> std::ops::Deref for WrapAsVctrs<T> {
    type Target = T;
    fn deref(&self) -> &T { &self.0 }
}
impl<T> std::ops::DerefMut for WrapAsVctrs<T> {
    fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T: IntoR> IntoR for WrapAsVctrs<T> {
    type Error = T::Error;
    fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
        self.0.try_into_sexp()
    }
    unsafe fn try_into_sexp_unchecked(self)
        -> Result<crate::SEXP, Self::Error> {
        unsafe { self.0.try_into_sexp_unchecked() }
    }
}wrap_marker!(
95    WrapAsVctrs,
96    "Return `T` with its named vctrs class, preserving its existing class hierarchy."
97);
98
99#[doc =
"Return an S7 target class and register the inherent method with `S7::convert`. The equivalent attribute is `s7(convert_to = \"Target\")`."]
#[repr(transparent)]
pub struct ConvertTo<T>(pub T);
#[automatically_derived]impl<T: ::core::fmt::Debug> ::core::fmt::Debug for
    ConvertTo<T> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f, "ConvertTo",
            &&self.0)
    }
}
#[automatically_derived]impl<T: ::core::clone::Clone> ::core::clone::Clone for
    ConvertTo<T> {
    #[inline]
    fn clone(&self) -> Self {
        ConvertTo(::core::clone::Clone::clone(&self.0))
    }
}
#[automatically_derived]impl<T: ::core::marker::Copy> ::core::marker::Copy for
    ConvertTo<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq>
    ::core::marker::StructuralPartialEq for ConvertTo<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq
    for ConvertTo<T> {
    #[inline]
    fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]impl<T: ::core::cmp::Eq> ::core::cmp::Eq for
    ConvertTo<T> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) { let _: ::core::cmp::AssertParamIsEq<T>; }
}
#[automatically_derived]impl<T: ::core::cmp::PartialOrd>
    ::core::cmp::PartialOrd for ConvertTo<T> {
    #[inline]
    fn partial_cmp(&self, other: &Self)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::cmp::Ord> ::core::cmp::Ord for
    ConvertTo<T> {
    #[inline]
    fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
        ::core::cmp::Ord::cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::hash::Hash> ::core::hash::Hash for
    ConvertTo<T> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.0, state)
    }
}
#[automatically_derived]impl<T: ::core::default::Default>
    ::core::default::Default for ConvertTo<T> {
    #[inline]
    fn default() -> Self { ConvertTo(::core::default::Default::default()) }
}
impl<T> ConvertTo<T> {
    /// Wrap a value for an explicit R return class.
    pub const fn new(value: T) -> Self { Self(value) }
    /// Recover the Rust value.
    pub fn into_inner(self) -> T { self.0 }
}
impl<T> From<T> for ConvertTo<T> {
    fn from(value: T) -> Self { Self(value) }
}
impl<T> std::ops::Deref for ConvertTo<T> {
    type Target = T;
    fn deref(&self) -> &T { &self.0 }
}
impl<T> std::ops::DerefMut for ConvertTo<T> {
    fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T: IntoR> IntoR for ConvertTo<T> {
    type Error = T::Error;
    fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
        self.0.try_into_sexp()
    }
    unsafe fn try_into_sexp_unchecked(self)
        -> Result<crate::SEXP, Self::Error> {
        unsafe { self.0.try_into_sexp_unchecked() }
    }
}wrap_marker!(
100    ConvertTo,
101    "Return an S7 target class and register the inherent method with `S7::convert`. The equivalent attribute is `s7(convert_to = \"Target\")`."
102);
103#[doc =
"Return the enclosing S7 class from a static conversion method. Its sole typed source parameter determines the `s7(convert_from = \"Source\")` registration."]
#[repr(transparent)]
pub struct ConvertFrom<T>(pub T);
#[automatically_derived]impl<T: ::core::fmt::Debug> ::core::fmt::Debug for
    ConvertFrom<T> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f, "ConvertFrom",
            &&self.0)
    }
}
#[automatically_derived]impl<T: ::core::clone::Clone> ::core::clone::Clone for
    ConvertFrom<T> {
    #[inline]
    fn clone(&self) -> Self {
        ConvertFrom(::core::clone::Clone::clone(&self.0))
    }
}
#[automatically_derived]impl<T: ::core::marker::Copy> ::core::marker::Copy for
    ConvertFrom<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq>
    ::core::marker::StructuralPartialEq for ConvertFrom<T> {
}
#[automatically_derived]impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq
    for ConvertFrom<T> {
    #[inline]
    fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]impl<T: ::core::cmp::Eq> ::core::cmp::Eq for
    ConvertFrom<T> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) { let _: ::core::cmp::AssertParamIsEq<T>; }
}
#[automatically_derived]impl<T: ::core::cmp::PartialOrd>
    ::core::cmp::PartialOrd for ConvertFrom<T> {
    #[inline]
    fn partial_cmp(&self, other: &Self)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::cmp::Ord> ::core::cmp::Ord for
    ConvertFrom<T> {
    #[inline]
    fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
        ::core::cmp::Ord::cmp(&self.0, &other.0)
    }
}
#[automatically_derived]impl<T: ::core::hash::Hash> ::core::hash::Hash for
    ConvertFrom<T> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.0, state)
    }
}
#[automatically_derived]impl<T: ::core::default::Default>
    ::core::default::Default for ConvertFrom<T> {
    #[inline]
    fn default() -> Self { ConvertFrom(::core::default::Default::default()) }
}
impl<T> ConvertFrom<T> {
    /// Wrap a value for an explicit R return class.
    pub const fn new(value: T) -> Self { Self(value) }
    /// Recover the Rust value.
    pub fn into_inner(self) -> T { self.0 }
}
impl<T> From<T> for ConvertFrom<T> {
    fn from(value: T) -> Self { Self(value) }
}
impl<T> std::ops::Deref for ConvertFrom<T> {
    type Target = T;
    fn deref(&self) -> &T { &self.0 }
}
impl<T> std::ops::DerefMut for ConvertFrom<T> {
    fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T: IntoR> IntoR for ConvertFrom<T> {
    type Error = T::Error;
    fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
        self.0.try_into_sexp()
    }
    unsafe fn try_into_sexp_unchecked(self)
        -> Result<crate::SEXP, Self::Error> {
        unsafe { self.0.try_into_sexp_unchecked() }
    }
}wrap_marker!(
104    ConvertFrom,
105    "Return the enclosing S7 class from a static conversion method. Its sole typed source parameter determines the `s7(convert_from = \"Source\")` registration."
106);