syntree::pointer

Trait Pointer

Source
pub trait Pointer:
    Sized
    + Copy
    + Hash
    + Eq
    + Debug
    + Sealed {
    // Required methods
    fn new(value: usize) -> Option<Self>;
    fn get(self) -> usize;
}
Expand description

A pointer type that is derived from the pointer Width.

Required Methods§

Source

fn new(value: usize) -> Option<Self>

Safe constructor for the pointer.

Returns None if the value provided is out of bounds for the pointer type.

§Examples
use syntree::pointer::{Pointer, PointerU32};

let v = PointerU32::new(0).ok_or("out of bounds")?;
assert_eq!(v.get(), 0);
let v = PointerU32::new(42).ok_or("out of bounds")?;
assert_eq!(v.get(), 42);
Source

fn get(self) -> usize

Get the index of a pointer.

§Examples
use syntree::pointer::{Pointer, PointerU32};

let v = PointerU32::new(0).ok_or("out of bounds")?;
assert_eq!(v.get(), 0);
let v = PointerU32::new(42).ok_or("out of bounds")?;
assert_eq!(v.get(), 42);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Pointer for PointerU8

Pointer used for u8 type.

use syntree::pointer::Pointer;
use syntree::pointer::PointerU8;

 let v = PointerU8::new(0).ok_or("out of bounds")?;
assert_eq!(v.get(), 0);
 let v = PointerU8::new(42).ok_or("out of bounds")?;
assert_eq!(v.get(), 42);
Source§

impl Pointer for PointerU16

Pointer used for u16 type.

use syntree::pointer::Pointer;
use syntree::pointer::PointerU16;

 let v = PointerU16::new(0).ok_or("out of bounds")?;
assert_eq!(v.get(), 0);
 let v = PointerU16::new(42).ok_or("out of bounds")?;
assert_eq!(v.get(), 42);
Source§

impl Pointer for PointerU32

Pointer used for u32 type.

use syntree::pointer::Pointer;
use syntree::pointer::PointerU32;

 let v = PointerU32::new(0).ok_or("out of bounds")?;
assert_eq!(v.get(), 0);
 let v = PointerU32::new(42).ok_or("out of bounds")?;
assert_eq!(v.get(), 42);
Source§

impl Pointer for PointerU64

Pointer used for u64 type.

use syntree::pointer::Pointer;
use syntree::pointer::PointerU64;

 let v = PointerU64::new(0).ok_or("out of bounds")?;
assert_eq!(v.get(), 0);
 let v = PointerU64::new(42).ok_or("out of bounds")?;
assert_eq!(v.get(), 42);
Source§

impl Pointer for PointerU128

Pointer used for u128 type.

use syntree::pointer::Pointer;
use syntree::pointer::PointerU128;

 let v = PointerU128::new(0).ok_or("out of bounds")?;
assert_eq!(v.get(), 0);
 let v = PointerU128::new(42).ok_or("out of bounds")?;
assert_eq!(v.get(), 42);
Source§

impl Pointer for PointerUsize

Pointer used for usize type.

use syntree::pointer::Pointer;
use syntree::pointer::PointerUsize;

 let v = PointerUsize::new(0).ok_or("out of bounds")?;
assert_eq!(v.get(), 0);
 let v = PointerUsize::new(42).ok_or("out of bounds")?;
assert_eq!(v.get(), 42);