aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-10-31 20:59:38 -0700
committerSteven Fackler <[email protected]>2016-10-31 21:00:26 -0700
commitab30ad0ce76ee6fd8cc14ecff2186171c7f610e3 (patch)
treef855b70ba26f82e6545e8e2557cc5eb0c5574fae /openssl/src
parentRemove Opaque (diff)
downloadrust-openssl-ab30ad0ce76ee6fd8cc14ecff2186171c7f610e3.tar.xz
rust-openssl-ab30ad0ce76ee6fd8cc14ecff2186171c7f610e3.zip
Documentation
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/types.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/openssl/src/types.rs b/openssl/src/types.rs
index 7302bca9..40831ee8 100644
--- a/openssl/src/types.rs
+++ b/openssl/src/types.rs
@@ -1,25 +1,38 @@
+//! 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 {
+ /// The raw C type.
type 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>);
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> {
&*(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> {
&mut *(ptr as *mut _)
}
+ /// Returns a pointer to its raw type.
pub fn as_ptr(&self) -> *mut T::CType {
self as *const _ as *mut _
}