Skip to content

Run analysis for size and alignment of non-primitive types #242

Open
@Mec-iS

Description

@Mec-iS

Run a check using std::mem to check for example:

trait Position {}

struct Coordinates(f64, f64);

impl Position for Coordinates {}

fn main() {
    let val = Coordinates(1.0, 2.0);
    let ref_: &Coordinates = &val;
    let pos_ref: &Position = &val as &Position;
    let ptr:       *const Coordinates = &val as *const Coordinates;
    let pos_ptr: *const Position  = &val as *const Position;
    
    println!("ref_: {}", std::mem::size_of_val(&ref_));
    println!("ptr: {}", std::mem::size_of_val(&ptr));
    println!("val: {}", std::mem::size_of_val(&val));
    println!("pos_ref: {}", std::mem::size_of_val(&pos_ref));
    println!("pos_ptr: {}", std::mem::size_of_val(&pos_ptr));
}

size of value and position in memory. About alignment see here.
On the side, is there a way we can use const fn somewhere if the custom traits to have it computed at compile-time?

Metadata

Metadata

Assignees

No one assigned

    Labels

    explorativenot an actual issue. Just a thing to look into

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions