Cast through a thin pointer first

    pub fn done_visit(&mut self, node: &dyn FrpNodeAny) {
        let n = node as *const dyn FrpNodeAny;
        let a = n as usize;
        todo!()
    }

gets compile error of:

   |
31 |         let a = n as usize;
   |                 ^^^^^^^^^^
   |
   = help: cast through a thin pointer first

This confuses me as I thought the standard way to do "&T" to "usize" is to do "&T as *const T as usize"

1 Like

That's because the size of &/*[const | mut] dyn Trait is the size of 2 usizes. You'd need to do:

let a = n as *const () as usize;

Since then the compiler can turn n (which is 2 usizes) into one usize and then get the numeric value of that.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.