rune::alloc::limit

Function get

Source
pub fn get() -> usize
Expand description

Get remaining memory that may be allocated.

ยงExamples

Example dealing with trait objects that were allocated externally:

use rune::alloc::{Box, Vec};
use rune::alloc::limit;
use std::boxed::Box as StdBox;

assert_eq!(limit::get(), usize::MAX);

let b: StdBox<dyn Iterator<Item = u32>> = StdBox::new(1..3);
let mut b = Box::from_std(b)?;
assert_eq!(b.next(), Some(1));
assert_eq!(b.next(), Some(2));
assert_eq!(b.next(), None);

assert!(limit::get() < usize::MAX);
drop(b);

assert_eq!(limit::get(), usize::MAX);