building with stable rust instead of nightly
Closed this issue · 3 comments
I would like to use this crate without having to rely on the nightly toolchain. I could build clingo-rs with the stable toolchain (using rust 1.31) after replacing std::ptr::Unique with std::ptr::NonNull (according to rust-lang/rust#27730, Unique will remain unstable for ever).
After this change, "cargo test" fails (but it was already failing before) but all examples seem to run properly.
Do you think it is a valid change or is there something which can be corrupted by using NonNull instead of Unique?
Yes, doc tests are failing because of some example code in the doc strings.
I should add an ignore to this code.
For replacing Unique:
I'm not an expert on this, but from what I read it is probably the safer to use *mut T.
Do you have other reasons to use NonNull?
I'm new to rust and I'm not sure why Unique was here in the first place so I mostly tried NonNull after getting the following compiler message:
use of unstable library feature 'ptr_internals': use NonNull instead and consider PhantomData (if you also use #[may_dangle]), Send, and/or Sync
From what I understand, replacing Unique with NonNull is trivial and makes it clear that the pointer is valid, while switching to *mut seems to require slightly more work .
- 2 match blocks are used to guard the creation of the struct holding the pointer, they can be replaced by a direct is_null() check
- it is accessed through as_ptr() everywhere else, so there are about 20 such calls to remove.
The build and example work with these two options, I can prepare a pull request with the one you prefer.
With using NotNull you give the compiler a guarantee so checks can be optimized. The guarantees are actually weaker than Unique so replacing it should not create safety problems.