aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/stack.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2018-05-20 15:24:38 -0700
committerSteven Fackler <[email protected]>2018-05-20 15:24:38 -0700
commit3ab1cc7a8f259ecc858bbc6fe28d9611802d0591 (patch)
tree016c9c42b3077b8769d4d6e221abd123ea72c7ea /openssl/src/stack.rs
parentMerge pull request #924 from sfackler/libressl-alpn (diff)
downloadrust-openssl-3ab1cc7a8f259ecc858bbc6fe28d9611802d0591.tar.xz
rust-openssl-3ab1cc7a8f259ecc858bbc6fe28d9611802d0591.zip
Make Stack Sync + Send
Diffstat (limited to 'openssl/src/stack.rs')
-rw-r--r--openssl/src/stack.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/openssl/src/stack.rs b/openssl/src/stack.rs
index 4d5c0a13..ac1e2a13 100644
--- a/openssl/src/stack.rs
+++ b/openssl/src/stack.rs
@@ -40,15 +40,8 @@ pub trait Stackable: ForeignType {
/// An owned stack of `T`.
pub struct Stack<T: Stackable>(*mut T::StackType);
-impl<T: Stackable> Stack<T> {
- pub fn new() -> Result<Stack<T>, ErrorStack> {
- unsafe {
- ffi::init();
- let ptr = cvt_p(OPENSSL_sk_new_null())?;
- Ok(Stack(ptr as *mut _))
- }
- }
-}
+unsafe impl<T: Stackable + Send> Send for Stack<T> {}
+unsafe impl<T: Stackable + Sync> Sync for Stack<T> {}
impl<T: Stackable> Drop for Stack<T> {
fn drop(&mut self) {
@@ -59,6 +52,16 @@ impl<T: Stackable> Drop for Stack<T> {
}
}
+impl<T: Stackable> Stack<T> {
+ pub fn new() -> Result<Stack<T>, ErrorStack> {
+ unsafe {
+ ffi::init();
+ let ptr = cvt_p(OPENSSL_sk_new_null())?;
+ Ok(Stack(ptr as *mut _))
+ }
+ }
+}
+
impl<T: Stackable> iter::IntoIterator for Stack<T> {
type IntoIter = IntoIter<T>;
type Item = T;
@@ -164,6 +167,9 @@ impl<T: Stackable> ExactSizeIterator for IntoIter<T> {}
pub struct StackRef<T: Stackable>(Opaque, PhantomData<T>);
+unsafe impl<T: Stackable + Send> Send for StackRef<T> {}
+unsafe impl<T: Stackable + Sync> Sync for StackRef<T> {}
+
impl<T: Stackable> ForeignTypeRef for StackRef<T> {
type CType = T::StackType;
}