title: How can I call a raw address from Rust?
body: <p>I am writing an OS in Rust and need to directly call into a virtual address that I'm calculating (of type <code>u32</code>). I expected this to be relatively simple:</p>
  <pre><code>let code = virtual_address as (extern &quot;C&quot; fn ());
  (code)();
  </code></pre>
  <p>However, this complains that the cast is non-primitive. It suggests I use the <code>From</code> trait, but I don't see how this could help (although I am relatively new to Rust and so could be missing something).</p>
  <pre class="lang-none prettyprint-override"><code>error[E0605]: non-primitive cast: `u32` as `extern &quot;C&quot; fn()`
   --&gt; src/main.rs:3:16
    |
  3 |     let code = virtual_address as (extern &quot;C&quot; fn ());
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
  </code></pre>
  <p>I have everything in <code>libcore</code> at my disposal, but haven't ported <code>std</code> and so can't rely on anything that isn't no_std</p>