aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/types.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-11-04 16:32:20 -0700
committerSteven Fackler <[email protected]>2016-11-04 17:16:59 -0700
commit01ae978db0dc8620b2cc754c0d5cf94a68c1f549 (patch)
treebc9a3bc83a1efe4853628a1c56eca8af75e079c9 /openssl/src/types.rs
parentMake utility functions private (diff)
downloadrust-openssl-01ae978db0dc8620b2cc754c0d5cf94a68c1f549.tar.xz
rust-openssl-01ae978db0dc8620b2cc754c0d5cf94a68c1f549.zip
Get rid of Ref
There's unfortunately a rustdoc bug that causes all methods implemented for any Ref<T> to be inlined in the deref methods section :(
Diffstat (limited to 'openssl/src/types.rs')
-rw-r--r--openssl/src/types.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/openssl/src/types.rs b/openssl/src/types.rs
index 40831ee8..2fadfd42 100644
--- a/openssl/src/types.rs
+++ b/openssl/src/types.rs
@@ -1,39 +1,40 @@
//! Items used by other types.
-use std::cell::UnsafeCell;
-use std::marker::PhantomData;
-
/// A type implemented by wrappers over OpenSSL types.
///
/// This should not be implemented by anything outside of this crate; new methods may be added at
/// any time.
-pub unsafe trait OpenSslType {
+pub trait OpenSslType: Sized {
/// The raw C type.
type CType;
+ /// The type representing a reference to this type.
+ type Ref: OpenSslTypeRef<CType = Self::CType>;
+
/// Constructs an instance of this type from its raw type.
unsafe fn from_ptr(ptr: *mut Self::CType) -> Self;
-
- /// Returns a pointer to its raw type.
- fn as_ptr(&self) -> *mut Self::CType;
}
-/// A reference to an OpenSSL type.
-pub struct Ref<T>(UnsafeCell<()>, PhantomData<T>);
+/// A trait implemented by types which reference borrowed OpenSSL types.
+///
+/// This should not be implemented by anything outside of this crate; new methods may be added at
+/// any time.
+pub trait OpenSslTypeRef: Sized {
+ /// The raw C type.
+ type CType;
-impl<T: OpenSslType> Ref<T> {
- /// Constructs a shared reference to this type from its raw type.
- pub unsafe fn from_ptr<'a>(ptr: *mut T::CType) -> &'a Ref<T> {
+ /// Constructs a shared instance of this type from its raw type.
+ unsafe fn from_ptr<'a>(ptr: *mut Self::CType) -> &'a Self {
&*(ptr as *mut _)
}
- /// Constructs a mutable reference to this type from its raw type.
- pub unsafe fn from_ptr_mut<'a>(ptr: *mut T::CType) -> &'a mut Ref<T> {
+ /// Constructs a mutable reference of this type from its raw type.
+ unsafe fn from_ptr_mut<'a>(ptr: *mut Self::CType) -> &'a mut Self {
&mut *(ptr as *mut _)
}
- /// Returns a pointer to its raw type.
- pub fn as_ptr(&self) -> *mut T::CType {
+ /// Returns a raw pointer to the wrapped value.
+ fn as_ptr(&self) -> *mut Self::CType {
self as *const _ as *mut _
}
}