rust - Raw pointer type for interior mutable struct -
i’m doing rust ffi work erlang nif api, , have these:
erlnifenv *enif_alloc_env(); void enif_free_env(erlnifenv* env); this erlnifenv pointer gets passed variety of other functions user never deref pointer. also, pointer not threadsafe (use amongst multiple threads require mutex). naive rust representation of type be..
struct erlnifenv; *mut erlnifenv; but, think can treat type having “interior mutability” lead to…
struct erlnifenv; *const erlnifenv; should treating pointer const though underlying c code sees non-const?
i think should treat them treat references in rust itself. when function requires &mut reference, change value, , if requires &, natural expect value won't changed (of course, disregarding inner mutability).
c not have distinction between inherited , inner mutability, , can choose use *mut or *const solely based on how c functions work value. in fact, in written c api distinction present in form of const qualifiers. consequently, if there functions want mutate value, go *mut. if there no such functions (e.g. immutable structure created once) go *const. is, of course, applies type want store in wrapper - in ffi function signatures should mirror c api signatures.
Comments
Post a Comment