Skip to content

Commit 9a398bc

Browse files
committed
fix nightly and clippy
1 parent 32dc01d commit 9a398bc

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

src/lib.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
const_panic,
1515
const_fn,
1616
const_mut_refs,
17+
const_raw_ptr_deref,
1718
)
1819
)]
1920
#![cfg_attr(feature = "nightly", forbid(unsafe_op_in_unsafe_fn))]
@@ -117,15 +118,33 @@
117118
//! assert_eq!(std::mem::size_of_val(&vec), std::mem::size_of::<usize>());
118119
//! ```
119120
//!
120-
//! ## Nightly
121+
//! ## `alloc`
122+
//!
123+
//! A [`HeapVec`] is just [`Vec`], but built atop [`GenericVec`],
124+
//! meaning you get all the features of [`GenericVec`] for free! But this
125+
//! requries either the `alloc` or `std` feature to be enabled.
126+
//!
127+
//! ```rust
128+
//! use generic_vec::{HeapVec, gvec};
129+
//! let mut vec: HeapVec<u32> = gvec![1, 2, 3, 4];
130+
//! assert_eq!(vec.capacity(), 4);
131+
//! vec.extend(&[5, 6, 7, 8]);
132+
//!
133+
//! assert_eq!(vec, [1, 2, 3, 4, 5, 6, 7, 8]);
134+
//!
135+
//! vec.try_push(5).expect_err("Tried to push past capacity!");
136+
//! ```
137+
//!
138+
//! ## `nightly`
121139
//!
122140
//! If you enable the nightly feature then you gain access to
123141
//! [`ArrayVec`] and [`InitArrayVec`]. These are just like the
124142
//! slice versions, but since they own their data, they can be
125143
//! freely moved around, unconstrained. You can also create
126144
//! a new [`ArrayVec`] without passing in an existing buffer.
127145
//!
128-
//! ```rust,ignore
146+
//! ```rust
147+
//! # #![cfg_attr(not(feature = "nightly"), ignore)]
129148
//! use generic_vec::ArrayVec;
130149
//!
131150
//! let mut array_vec = ArrayVec::<i32, 16>::new();
@@ -140,10 +159,6 @@
140159
//! The distinction between [`ArrayVec`] and [`InitArrayVec`]
141160
//! is identical to their slice counterparts.
142161
//!
143-
//! Finally a [`HeapVec`] is just [`Vec`], but built atop [`GenericVec`],
144-
//! meaning you get all the features of [`GenericVec`] for free! But this
145-
//! requries either the `alloc` or `std` feature to be enabled.
146-
//!
147162
//! Note on the documentation: if the feature exists on [`Vec`], then the documentation
148163
//! is either exactly the same as [`Vec`] or slightly adapted to better fit [`GenericVec`]
149164
@@ -409,6 +424,7 @@ impl<T, B, A> TypeVec<T, B, A> {
409424
/// Create a new [`TypeVec`] with the given alignment type
410425
pub const fn with_align() -> Self {
411426
#[cfg(not(feature = "nightly"))]
427+
#[allow(clippy::no_effect)]
412428
{
413429
[()][(!<raw::UninitBuffer<B, A> as raw::Storage<T>>::IS_ALIGNED) as usize];
414430
}

src/raw/slice.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,22 @@ impl<T> UninitSlice<T> {
1919
/// # Safety
2020
///
2121
/// You may not write uninitialized memory to this slice
22-
pub unsafe fn into_mut(&mut self) -> &mut [MaybeUninit<T>] { unsafe { &mut *(self as *mut Self as *mut [_]) } }
22+
pub unsafe fn to_mut(&mut self) -> &mut [MaybeUninit<T>] { unsafe { &mut *(self as *mut Self as *mut [_]) } }
2323
}
2424

2525
#[cfg(feature = "nightly")]
26-
impl<'a, T> UninitSlice<'a, T> {
26+
impl<T> UninitSlice<T> {
2727
/// Create a new `UninitSlice` storage
28-
pub const fn new(buffer: &'a mut [MaybeUninit<T>]) -> Self { Self(buffer) }
29-
30-
/// Reborrow an `UninitSlice` storage
31-
pub const fn as_ref(&mut self) -> UninitSlice<'_, T> { UninitSlice(self.0) }
28+
pub const fn from_mut(buffer: &mut [MaybeUninit<T>]) -> &mut Self {
29+
unsafe { &mut *(buffer as *mut [_] as *mut Self) }
30+
}
3231

3332
/// Get the backing value of the this `Uninit` storage
3433
///
3534
/// # Safety
3635
///
3736
/// You may not write uninitialized memory to this slice
38-
pub const unsafe fn into_inner(self) -> &'a mut [MaybeUninit<T>] { self.0 }
37+
pub const unsafe fn to_mut(&mut self) -> &mut [MaybeUninit<T>] { unsafe { &mut *(self as *mut Self as *mut [_]) } }
3938
}
4039

4140
unsafe impl<T, U> Storage<U> for UninitSlice<T> {

0 commit comments

Comments
 (0)