Skip to main content

RamFn

Trait RamFn 

Source
pub trait RamFn {
    type Fn;

    const MAX: usize;

    // Required methods
    fn src(&self) -> *const u8;
    fn len(&self) -> usize;
    fn rom(&self) -> Self::Fn;
    unsafe fn install<const N: usize>(&self, dst: *mut [u8; N]) -> Self::Fn;
}
Expand description

Shared interface for functions defined with ram_fn.

Each ram_fn produces a zero-sized handle that implements this trait; the associated Fn type carries the function’s own signature.

Required Associated Constants§

Source

const MAX: usize

The declared maximum compiled size, in bytes (from #[ram_fn(max = N)]).

Required Associated Types§

Source

type Fn

Function-pointer type carrying the defined function’s signature.

Required Methods§

Source

fn src(&self) -> *const u8

Address of the function’s machine code in ROM.

Source

fn len(&self) -> usize

Length of the machine code, in bytes.

Source

fn rom(&self) -> Self::Fn

The ROM-resident copy as a callable pointer.

Source

unsafe fn install<const N: usize>(&self, dst: *mut [u8; N]) -> Self::Fn

Copy the code into dst and return the RAM copy as a callable pointer.

dst is a fixed-size buffer; N >= MAX is checked at compile time, so the buffer is large enough for any function within its declared max. No runtime length check is needed.

§Safety

dst must point to executable RAM that stays live and unchanged for as long as the returned pointer is called.

install also assumes the function fits MAX and is position independent. Both are verified only by cargo-gb over the linked ROM (see the crate docs); built another way, install may overflow dst or return a pointer to code that does not run correctly when relocated.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§