psm

Enum StackDirection

Source
pub enum StackDirection {
    Ascending = 1,
    Descending = 2,
}
Expand description

The direction into which stack grows as stack frames are made.

This is a target-specific property that can be obtained at runtime by calling StackDirection::new().

Variants§

§

Ascending = 1

§

Descending = 2

Implementations§

Source§

impl StackDirection

Source

pub fn new() -> StackDirection

Obtain the stack growth direction.

Examples found in repository?
examples/info.rs (line 7)
5
6
7
8
        fn main() {
            println!("Stack is {:?} and is at {:p} currently",
                     psm::StackDirection::new(), psm::stack_pointer());
        }
More examples
Hide additional examples
examples/on_stack_fibo.rs (line 43)
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
        fn main() {
            let mut stack_size = 1024 * 128;
            unsafe {
                for &(n, expected) in FIB_COUNTS.iter() {
                    loop {
                        println!("fib({}) with {} bytes of stack", n, stack_size - STACK_REDLINE);
                        let layout = alloc::Layout::from_size_align(stack_size, STACK_ALIGN).unwrap();
                        let new_stack = alloc::alloc(layout);
                        assert!(!new_stack.is_null(), "allocations must succeed!");
                        let max_stack = match psm::StackDirection::new() {
                            psm::StackDirection::Ascending =>
                                new_stack.offset((stack_size - STACK_REDLINE) as isize),
                            psm::StackDirection::Descending =>
                                new_stack.offset(STACK_REDLINE as isize),
                        };
                        let result = psm::on_stack(new_stack, stack_size, || {
                            fib(n, max_stack)
                        });
                        alloc::dealloc(new_stack, layout);
                        if let Some(res) = result {
                            assert_eq!(res, expected);
                            println!("fib({}) = {}", n, res);
                            break;
                        } else {
                            println!("Stack not large enough!");
                            stack_size *= 2;
                        }
                    }
                }
            }
        }

Trait Implementations§

Source§

impl Clone for StackDirection

Source§

fn clone(&self) -> StackDirection

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StackDirection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for StackDirection

Source§

fn eq(&self, other: &StackDirection) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for StackDirection

Source§

impl Eq for StackDirection

Source§

impl StructuralPartialEq for StackDirection

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.