fn test1(arg: *const u8) {}
fn test2(arg: Option<&u8>) {}
fn test3(arg: &u8) (}
Assuming arg
is a valid pointer, are test1
and test2
equivalent? Also, assuming arg can't be null, are they equivalent to test3
? mem::size_of
tells me they have the same size, but is it a guaranty of the language?
Same thing with structs:
struct S1 {
a: *const u8,
}
struct S2 {
a: Option<&u8>,
}
struct S3 {
a: &u8,
}
1 Like
More background: I'm doing an implementation of libvulkan.so. The error checking in Vulkan is very minimal, the driver don't have to validate every piece of input. During development, you can active middlewares to verify that the application effectively uses correctly the API. For example, in vkCreateBuffer, the Valid Usage section dictates that pBuffer
must be a pointer to a valid instance of VkBuffer
. For convenience, I would like pBuffer
to be of type &mut VkBuffer
instead of *const VkBuffer
. As I can have C code calling my code, I can do that if they are equivalent.