Is this worked? from *const T to *mut T

Is this possible to cast between raw pointers?

  1. *const T to *mut T


  1. *mut T to *const T

if its possible pls provide an example

Thank you

Yes, it's possible, just cast it with the as operator

fn as_mut_ptr<T>(ptr: *const T) -> *mut T {
    ptr as *mut T

fn as_const_ptr<T>(ptr: *mut T) -> *const T {
    ptr as *const T

Notice that this was also posted on reddit:

Please make sure to link other posts when you post the same question multiple times.

Duplicate of: *const T to *mut T?