2015-04-16 11:37:17 +08:00
|
|
|
//! Traits for stacks.
|
2015-04-16 16:14:18 +08:00
|
|
|
use core::prelude::*;
|
2015-04-16 11:37:17 +08:00
|
|
|
|
|
|
|
/// A trait for objects that hold ownership of a stack.
|
2015-01-14 15:31:17 +08:00
|
|
|
pub trait Stack {
|
2015-04-16 11:37:17 +08:00
|
|
|
/// Returns the top of the stack.
|
|
|
|
/// On all modern architectures, the stack grows downwards,
|
|
|
|
/// so this is the highest address.
|
2015-01-14 15:31:17 +08:00
|
|
|
fn top(&mut self) -> *mut u8;
|
2015-04-16 11:37:17 +08:00
|
|
|
/// Returns the bottom of the stack.
|
|
|
|
/// On all modern architectures, the stack grows downwards,
|
|
|
|
/// so this is the lowest address.
|
2015-01-14 15:31:17 +08:00
|
|
|
fn limit(&self) -> *const u8;
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
2015-04-16 03:56:57 +08:00
|
|
|
|
2015-04-16 11:37:17 +08:00
|
|
|
/// A trait for objects that provide stacks of arbitrary size.
|
2015-04-16 03:56:57 +08:00
|
|
|
pub trait StackSource {
|
|
|
|
type Output: Stack;
|
2015-04-16 16:14:18 +08:00
|
|
|
type Error = ();
|
|
|
|
fn get_stack(size: usize) -> Result<Self::Output, Self::Error>;
|
2015-04-16 03:56:57 +08:00
|
|
|
}
|