Skip to content

Instantly share code, notes, and snippets.

@SiegeLord
Created April 13, 2013 04:59
Show Gist options
  • Select an option

  • Save SiegeLord/5377002 to your computer and use it in GitHub Desktop.

Select an option

Save SiegeLord/5377002 to your computer and use it in GitHub Desktop.
Inherited mutability
struct c_struct;
unsafe fn c_function(a : *mut c_struct)
{
}
struct wrapper
{
payload : *c_struct
}
fn create() -> wrapper
{
unsafe
{
wrapper{payload : ptr::null()}
}
}
fn function(a : &mut wrapper)
{
unsafe
{
c_function(a.payload);
}
}
fn main()
{
let mut w = ~create();
function(w);
}
/*
bin.rs:25:19: 25:28 error: mismatched types: expected `*mut c_struct` but found `*c_struct` (values differ in mutability)
bin.rs:25 c_function(a.payload);
^~~~~~~~~
error: aborting due to previous error
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment