Trait gear_core::pages::PageU32Size
source · pub trait PageU32Size: PageNumber {
Show 23 methods
// Required methods
fn size_non_zero() -> NonZeroU32;
unsafe fn new_unchecked(num: u32) -> Self;
// Provided methods
fn size() -> u32 { ... }
fn from_offset(offset: u32) -> Self { ... }
fn new(num: u32) -> Result<Self, PageError> { ... }
fn offset(&self) -> u32 { ... }
fn end_offset(&self) -> u32 { ... }
fn to_page<P1: PageU32Size>(&self) -> P1 { ... }
fn to_last_page<P1: PageU32Size>(&self) -> P1 { ... }
fn add_raw(&self, raw: u32) -> Result<Self, PageError> { ... }
fn sub_raw(&self, raw: u32) -> Result<Self, PageError> { ... }
fn add(&self, other: Self) -> Result<Self, PageError> { ... }
fn sub(&self, other: Self) -> Result<Self, PageError> { ... }
fn inc(&self) -> Result<Self, PageError> { ... }
fn dec(&self) -> Result<Self, PageError> { ... }
fn align_down(&self, size: NonZeroU32) -> Self { ... }
fn zero() -> Self { ... }
fn iter_count(&self, count: Self) -> Result<PagesIter<Self>, PageError> { ... }
fn iter_end(&self, end: Self) -> Result<PagesIter<Self>, PageError> { ... }
fn iter_from_zero_inclusive(&self) -> PagesIterInclusive<Self> ⓘ { ... }
fn iter_from_zero(&self) -> PagesIter<Self> ⓘ { ... }
fn iter_once(&self) -> PagesIterInclusive<Self> ⓘ { ... }
fn to_pages_iter<P: PageU32Size>(&self) -> PagesIterInclusive<P> ⓘ { ... }
}Expand description
Trait represents page with u32 size for u32 memory: max memory size is 2^32 bytes. All operations with page guarantees, that no addr or page number can be overflowed.
Required Methods§
sourcefn size_non_zero() -> NonZeroU32
fn size_non_zero() -> NonZeroU32
Returns size of page.
sourceunsafe fn new_unchecked(num: u32) -> Self
unsafe fn new_unchecked(num: u32) -> Self
Constructs new page without any checks.
Safety
Doesn’t guarantee, that page offset or page end offset is in not overflowed.
Provided Methods§
sourcefn from_offset(offset: u32) -> Self
fn from_offset(offset: u32) -> Self
Constructs new page from byte offset: returns page which contains this byte.
sourcefn new(num: u32) -> Result<Self, PageError>
fn new(num: u32) -> Result<Self, PageError>
Constructs new page from raw page number with checks. Returns error if page will contain bytes, with offsets bigger then u32::MAX.
sourcefn end_offset(&self) -> u32
fn end_offset(&self) -> u32
Returns page last byte offset.
sourcefn to_page<P1: PageU32Size>(&self) -> P1
fn to_page<P1: PageU32Size>(&self) -> P1
Returns new page, which contains self zero byte.
sourcefn to_last_page<P1: PageU32Size>(&self) -> P1
fn to_last_page<P1: PageU32Size>(&self) -> P1
Returns new page, which contains self last byte.
sourcefn add_raw(&self, raw: u32) -> Result<Self, PageError>
fn add_raw(&self, raw: u32) -> Result<Self, PageError>
Returns page which has number page.raw() + raw, with checks.
sourcefn sub_raw(&self, raw: u32) -> Result<Self, PageError>
fn sub_raw(&self, raw: u32) -> Result<Self, PageError>
Returns page which has number page.raw() - raw, with checks.
sourcefn add(&self, other: Self) -> Result<Self, PageError>
fn add(&self, other: Self) -> Result<Self, PageError>
Returns page which has number page.raw() + other.raw(), with checks.
sourcefn sub(&self, other: Self) -> Result<Self, PageError>
fn sub(&self, other: Self) -> Result<Self, PageError>
Returns page which has number page.raw() - other.raw(), with checks.
sourcefn inc(&self) -> Result<Self, PageError>
fn inc(&self) -> Result<Self, PageError>
Returns page which has number page.raw() + 1, with checks.
sourcefn dec(&self) -> Result<Self, PageError>
fn dec(&self) -> Result<Self, PageError>
Returns page which has number page.raw() - 1, with checks.
sourcefn align_down(&self, size: NonZeroU32) -> Self
fn align_down(&self, size: NonZeroU32) -> Self
Aligns page zero byte and returns page which contains this byte.
Normally if size % Self::size() == 0,
then aligned byte is zero byte of the returned page.
sourcefn iter_count(&self, count: Self) -> Result<PagesIter<Self>, PageError>
fn iter_count(&self, count: Self) -> Result<PagesIter<Self>, PageError>
Returns iterator self..self + count.
sourcefn iter_end(&self, end: Self) -> Result<PagesIter<Self>, PageError>
fn iter_end(&self, end: Self) -> Result<PagesIter<Self>, PageError>
Returns iterator self..end.
sourcefn iter_from_zero_inclusive(&self) -> PagesIterInclusive<Self> ⓘ
fn iter_from_zero_inclusive(&self) -> PagesIterInclusive<Self> ⓘ
Returns iterator 0..=self
sourcefn iter_from_zero(&self) -> PagesIter<Self> ⓘ
fn iter_from_zero(&self) -> PagesIter<Self> ⓘ
Returns iterator 0..self
sourcefn iter_once(&self) -> PagesIterInclusive<Self> ⓘ
fn iter_once(&self) -> PagesIterInclusive<Self> ⓘ
Returns iterator self..=self
sourcefn to_pages_iter<P: PageU32Size>(&self) -> PagesIterInclusive<P> ⓘ
fn to_pages_iter<P: PageU32Size>(&self) -> PagesIterInclusive<P> ⓘ
Returns an iterator that iterates over the range of pages from self to the end page,
inclusive. Each iteration yields a page of type P.
Example
use gear_core::pages::{PageU32Size, GearPage, PageNumber};
let new_page = GearPage::new(5).expect("cannot create page");
let pages_iter = new_page.to_pages_iter::<GearPage>();
for page in pages_iter {
println!("Page number: {}", page.raw());
}Generic Parameters
P: The type of pages in the iterator, which must implement thePageU32Sizetrait.