Add Stack::pop
This commit is contained in:
parent
52feaae59f
commit
ed69d6b037
|
|
@ -40,18 +40,7 @@ impl<T: Stackable> Stack<T> {
|
||||||
impl<T: Stackable> Drop for Stack<T> {
|
impl<T: Stackable> Drop for Stack<T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
loop {
|
while let Some(_) = self.pop() {}
|
||||||
let ptr = OPENSSL_sk_pop(self.as_stack());
|
|
||||||
|
|
||||||
if ptr.is_null() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the owned version of the object just to run
|
|
||||||
// its `drop` implementation and delete the item.
|
|
||||||
T::from_ptr(ptr as *mut _);
|
|
||||||
}
|
|
||||||
|
|
||||||
OPENSSL_sk_free(self.0 as *mut _);
|
OPENSSL_sk_free(self.0 as *mut _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -209,6 +198,18 @@ impl<T: Stackable> StackRef<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Removes the last element from the stack and returns it.
|
||||||
|
pub fn pop(&mut self) -> Option<T> {
|
||||||
|
unsafe {
|
||||||
|
let ptr = OPENSSL_sk_pop(self.as_stack());
|
||||||
|
if ptr.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(T::from_ptr(ptr as *mut _))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe fn _get(&self, idx: usize) -> *mut T::CType {
|
unsafe fn _get(&self, idx: usize) -> *mut T::CType {
|
||||||
OPENSSL_sk_value(self.as_stack(), idx as c_int) as *mut _
|
OPENSSL_sk_value(self.as_stack(), idx as c_int) as *mut _
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue