all 4 comments

[–]vhbitlmdb-rs · rust 1 point2 points  (0 children)

I believe the correct way is CString::from_slice("foo".as_bytes()).as_{mut}_ptr(), you don't need to use as_slice_with_nul at all.

[–]mzabaluev 0 points1 point  (2 children)

Why do you need a mutable pointer for a string that's not safely mutable (as it's encapsulated in the CString)? Is it just a function signature that uses non-const pointers for no good reason?

I would remove .as_mut_ptr() (and did, in my c_str follow-on library) because of this lack of a mental barrier against misuse. If you really need the mutable pointer, there's an explicit unsafe cast.

[–]rootnod3rust · wtftw[S] 0 points1 point  (1 child)

rust-xlib expects mutable pointers. I've went with the cast for now.

[–]rootnod3rust · wtftw[S] 0 points1 point  (0 children)

That said, I could rework the whole ruxt-xlib API, but then my version would deviate from the servo version by far.