there's not much context to draw a decisive conclusion, so I will try to make some guesses.
first of all, are you sure it's a segfault instead of a panic? since you have an .unwrap() in the code, it might just be a logic error in your application.
other than that, the most likely cause I would guess is the callback is being called multiple times, but you converted the pointer back into a Box in the callback, which means the callback can only be called once. when it is first called, it will drop the Box at return, so subsequent calls would get a dangling pointer.
to verify this hypothesis, try something like this:
-let data = Box::from_raw(user_data);
+let data = unsafe { &*user_data };
BTW, you can convert Arc into a raw pointer directly, no need to box it again, see Arc::into_raw(). nevertheless, but the extra level of indirection should not cause segfault, it's just less efficient.
other than that, the most likely cause I would guess is the callback is being called multiple times, but you converted the pointer back into a Box in the callback, which means the callback can only be called once. when it is first called, it will drop the Box at return, so subsequent calls would get a dangling pointer.
Indeed the callback is called multiple times
which means the callback can only be called once
How can I correct the fact that the callback can only be called once ?
Box is exclusively owned and has only one instance. Box::from_raw undoes previous into_raw and makes the Box memory-managed by Rust again, and Rust destroys it before the function returns.
Box::from_raw can never be called more than once on the same pointer.
You usually would not use Box::into_raw with callbacks called more than once, because you won't have any way to properly free the memory after the last call of the callback.
If the data is stored/owned by something in Rust that outlives all the callbacks, then keep the data there and just pass a plain pointer/reference (no extra box).
When you already have Arc, you don't need Box either. You can take reference to the data inside the Arc if it outlives the callbacks, or use Arc::clone(&a).into_raw() like you'd use Box::into_raw (but the same applies about Arc::from_raw, it will decrement refcount after it's dropped)