miniextendr_api/
visibility.rs1use crate::into_r::IntoR;
52
53#[repr(transparent)]
56#[derive(#[automatically_derived]
impl<T: ::core::fmt::Debug> ::core::fmt::Debug for Invisible<T> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Invisible",
&&self.0)
}
}Debug, #[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for Invisible<T> {
#[inline]
fn clone(&self) -> Self {
Invisible(::core::clone::Clone::clone(&self.0))
}
}Clone, #[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for Invisible<T> { }Copy, #[automatically_derived]
impl<T: ::core::cmp::PartialEq> ::core::marker::StructuralPartialEq for
Invisible<T> {
}
#[automatically_derived]
impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq for Invisible<T> {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl<T: ::core::cmp::Eq> ::core::cmp::Eq for Invisible<T> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) { let _: ::core::cmp::AssertParamIsEq<T>; }
}Eq, #[automatically_derived]
impl<T: ::core::cmp::PartialOrd> ::core::cmp::PartialOrd for Invisible<T> {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
}
}PartialOrd, #[automatically_derived]
impl<T: ::core::cmp::Ord> ::core::cmp::Ord for Invisible<T> {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}Ord, #[automatically_derived]
impl<T: ::core::hash::Hash> ::core::hash::Hash for Invisible<T> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]
impl<T: ::core::default::Default> ::core::default::Default for Invisible<T> {
#[inline]
fn default() -> Self { Invisible(::core::default::Default::default()) }
}Default)]
57pub struct Invisible<T>(pub T);
58
59#[repr(transparent)]
63#[derive(#[automatically_derived]
impl<T: ::core::fmt::Debug> ::core::fmt::Debug for Visible<T> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Visible",
&&self.0)
}
}Debug, #[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for Visible<T> {
#[inline]
fn clone(&self) -> Self { Visible(::core::clone::Clone::clone(&self.0)) }
}Clone, #[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for Visible<T> { }Copy, #[automatically_derived]
impl<T: ::core::cmp::PartialEq> ::core::marker::StructuralPartialEq for
Visible<T> {
}
#[automatically_derived]
impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq for Visible<T> {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl<T: ::core::cmp::Eq> ::core::cmp::Eq for Visible<T> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) { let _: ::core::cmp::AssertParamIsEq<T>; }
}Eq, #[automatically_derived]
impl<T: ::core::cmp::PartialOrd> ::core::cmp::PartialOrd for Visible<T> {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
}
}PartialOrd, #[automatically_derived]
impl<T: ::core::cmp::Ord> ::core::cmp::Ord for Visible<T> {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}Ord, #[automatically_derived]
impl<T: ::core::hash::Hash> ::core::hash::Hash for Visible<T> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]
impl<T: ::core::default::Default> ::core::default::Default for Visible<T> {
#[inline]
fn default() -> Self { Visible(::core::default::Default::default()) }
}Default)]
64pub struct Visible<T>(pub T);
65
66macro_rules! marker_impls {
67 ($name:ident) => {
68 impl<T> $name<T> {
69 #[inline]
71 pub const fn new(value: T) -> Self {
72 $name(value)
73 }
74
75 #[inline]
77 pub fn into_inner(self) -> T {
78 self.0
79 }
80 }
81
82 impl<T> From<T> for $name<T> {
83 #[inline]
84 fn from(value: T) -> Self {
85 $name(value)
86 }
87 }
88
89 impl<T> ::std::ops::Deref for $name<T> {
90 type Target = T;
91
92 #[inline]
93 fn deref(&self) -> &T {
94 &self.0
95 }
96 }
97
98 impl<T> ::std::ops::DerefMut for $name<T> {
99 #[inline]
100 fn deref_mut(&mut self) -> &mut T {
101 &mut self.0
102 }
103 }
104
105 impl<T: IntoR> IntoR for $name<T> {
107 type Error = T::Error;
108
109 #[inline]
110 fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
111 self.0.try_into_sexp()
112 }
113
114 #[inline]
115 unsafe fn try_into_sexp_unchecked(self) -> Result<crate::SEXP, Self::Error> {
116 unsafe { self.0.try_into_sexp_unchecked() }
118 }
119 }
120 };
121}
122
123impl<T> Invisible<T> {
#[inline]
pub const fn new(value: T) -> Self { Invisible(value) }
#[inline]
pub fn into_inner(self) -> T { self.0 }
}
impl<T> From<T> for Invisible<T> {
#[inline]
fn from(value: T) -> Self { Invisible(value) }
}
impl<T> ::std::ops::Deref for Invisible<T> {
type Target = T;
#[inline]
fn deref(&self) -> &T { &self.0 }
}
impl<T> ::std::ops::DerefMut for Invisible<T> {
#[inline]
fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T: IntoR> IntoR for Invisible<T> {
type Error = T::Error;
#[inline]
fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
self.0.try_into_sexp()
}
#[inline]
unsafe fn try_into_sexp_unchecked(self)
-> Result<crate::SEXP, Self::Error> {
unsafe { self.0.try_into_sexp_unchecked() }
}
}marker_impls!(Invisible);
124impl<T> Visible<T> {
#[inline]
pub const fn new(value: T) -> Self { Visible(value) }
#[inline]
pub fn into_inner(self) -> T { self.0 }
}
impl<T> From<T> for Visible<T> {
#[inline]
fn from(value: T) -> Self { Visible(value) }
}
impl<T> ::std::ops::Deref for Visible<T> {
type Target = T;
#[inline]
fn deref(&self) -> &T { &self.0 }
}
impl<T> ::std::ops::DerefMut for Visible<T> {
#[inline]
fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T: IntoR> IntoR for Visible<T> {
type Error = T::Error;
#[inline]
fn try_into_sexp(self) -> Result<crate::SEXP, Self::Error> {
self.0.try_into_sexp()
}
#[inline]
unsafe fn try_into_sexp_unchecked(self)
-> Result<crate::SEXP, Self::Error> {
unsafe { self.0.try_into_sexp_unchecked() }
}
}marker_impls!(Visible);
125
126#[cfg(test)]
127mod tests {
128 use super::*;
129
130 #[test]
131 fn markers_are_transparent_wrappers() {
132 let i = Invisible::new(41).into_inner() + 1;
133 assert_eq!(i, 42);
134 let mut v: Visible<Vec<i32>> = Visible::from(vec![1]);
135 v.push(2);
136 assert_eq!(v.len(), 2);
137 assert_eq!(*v, vec![1, 2]);
138 assert_eq!(Invisible(()), Invisible::default());
139 assert_eq!(
140 std::mem::size_of::<Invisible<u64>>(),
141 std::mem::size_of::<u64>()
142 );
143 }
144}