Usually, returning Box<SomeStruct> is the way that FFI is done, as Box<SomeStruct> is a simple C pointer. However, suppose I want to create an instance of SomeStruct using Rust's JNI. On java I should return a jlong with the pointer number. How can I do it? Interpreting the Box as a number would make it be dropped after returning, which would give undefined behaviour.
You can use unsafe { &*ptr } or unsafe { &mut *ptr } depending on if you need an immutable or mutable reference. Note that in case of a mutable reference you must ensure that there is no other reference to it (eg because another thread tried to call the same method)