Skip to content

Commit 0a25018

Browse files
committed
update docs
so that it shows on doc.rs
1 parent fdb15b2 commit 0a25018

File tree

9 files changed

+43
-41
lines changed

9 files changed

+43
-41
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
2-
*.lock
2+
*.lock
3+
regex*

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = 'generic-vec'
3-
version = '0.1.1'
3+
version = '0.1.2'
44
authors = ['RustyYato <[email protected]>']
55
edition = '2018'
66
license = 'MIT/Apache-2.0'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,6 @@ is either exactly the same as `Vec` or slightly adapted to better fit `GenericVe
167167
Note on implementation: large parts of the implementation came straight from `Vec`
168168
so thanks for the amazing reference `std`!
169169

170-
Current version: 0.1.1
170+
Current version: 0.1.2
171171

172172
License: MIT/Apache-2.0

src/impls.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,17 @@ impl<T, S: ?Sized + Storage<T>> BorrowMut<[T]> for GenericVec<T, S> {
8383
fn borrow_mut(&mut self) -> &mut [T] { self }
8484
}
8585

86-
#[cfg(feature = "nightly")]
86+
#[cfg(any(doc, feature = "nightly"))]
8787
impl<T, const N: usize> From<[T; N]> for crate::ArrayVec<T, N> {
8888
fn from(array: [T; N]) -> Self { Self::from_array(array) }
8989
}
9090

91-
#[cfg(feature = "nightly")]
91+
#[cfg(any(doc, feature = "nightly"))]
9292
impl<T: Copy, const N: usize> From<[T; N]> for crate::InitArrayVec<T, N> {
9393
fn from(array: [T; N]) -> Self { crate::InitArrayVec::<T, N>::new(array) }
9494
}
9595

96+
#[cfg(not(doc))]
9697
#[cfg(feature = "alloc")]
9798
#[cfg(not(feature = "nightly"))]
9899
impl<T> From<Vec<T>> for crate::HeapVec<T> {
@@ -107,8 +108,8 @@ impl<T> From<Vec<T>> for crate::HeapVec<T> {
107108
}
108109
}
109110

110-
#[cfg(feature = "alloc")]
111-
#[cfg(feature = "nightly")]
111+
#[cfg(any(doc, feature = "alloc"))]
112+
#[cfg(any(doc, feature = "nightly"))]
112113
impl<T, A: std::alloc::AllocRef> From<Vec<T, A>> for crate::HeapVec<T, A> {
113114
fn from(vec: Vec<T, A>) -> Self {
114115
let (ptr, len, cap, alloc) = vec.into_raw_parts_with_alloc();
@@ -122,6 +123,7 @@ impl<T, A: std::alloc::AllocRef> From<Vec<T, A>> for crate::HeapVec<T, A> {
122123
}
123124
}
124125

126+
#[cfg(not(doc))]
125127
#[cfg(feature = "alloc")]
126128
#[cfg(not(feature = "nightly"))]
127129
impl<T> From<crate::HeapVec<T>> for Vec<T> {
@@ -133,8 +135,8 @@ impl<T> From<crate::HeapVec<T>> for Vec<T> {
133135
}
134136
}
135137

136-
#[cfg(feature = "alloc")]
137-
#[cfg(feature = "nightly")]
138+
#[cfg(any(doc, feature = "alloc"))]
139+
#[cfg(any(doc, feature = "nightly"))]
138140
impl<T, A: std::alloc::AllocRef> From<crate::HeapVec<T, A>> for Vec<T, A> {
139141
fn from(vec: crate::HeapVec<T, A>) -> Self {
140142
let (length, alloc) = vec.into_raw_parts();

src/iter/drain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ impl<'a, T, S: ?Sized + Storage<T>> Drain<'a, T, S> {
1414

1515
impl<T, S: ?Sized + Storage<T>> FusedIterator for Drain<'_, T, S> {}
1616

17-
#[cfg(feature = "nightly")]
1817
impl<T, S: ?Sized + Storage<T>> ExactSizeIterator for Drain<'_, T, S> {
18+
#[cfg(feature = "nightly")]
1919
fn is_empty(&self) -> bool { self.raw.is_empty() }
2020
}
2121

src/lib.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,24 @@ use raw::Storage;
209209
pub use core;
210210

211211
/// A heap backed vector with a growable capacity
212-
#[cfg(all(feature = "alloc", feature = "nightly"))]
212+
#[cfg(any(doc, all(feature = "alloc", feature = "nightly")))]
213213
#[cfg_attr(doc, doc(cfg(all(feature = "alloc", feature = "nightly"))))]
214214
pub type HeapVec<T, A = std::alloc::Global> = GenericVec<T, raw::Heap<T, A>>;
215215

216216
/// A heap backed vector with a growable capacity
217-
#[cfg(all(feature = "alloc", not(feature = "nightly")))]
217+
#[cfg(all(not(doc), feature = "alloc", not(feature = "nightly")))]
218218
#[cfg_attr(doc, doc(cfg(feature = "alloc")))]
219219
pub type HeapVec<T> = GenericVec<T, raw::Heap<T>>;
220220

221221
/// An array backed vector backed by potentially uninitialized memory
222-
#[cfg(feature = "nightly")]
222+
#[cfg(any(doc, feature = "nightly"))]
223223
#[cfg_attr(doc, doc(cfg(feature = "nightly")))]
224224
pub type ArrayVec<T, const N: usize> = TypeVec<T, [T; N]>;
225225
/// An slice backed vector backed by potentially uninitialized memory
226226
pub type SliceVec<'a, T> = GenericVec<T, &'a mut raw::UninitSlice<T>>;
227227

228228
/// An array backed vector backed by initialized memory
229-
#[cfg(feature = "nightly")]
229+
#[cfg(any(doc, feature = "nightly"))]
230230
#[cfg_attr(doc, doc(cfg(feature = "nightly")))]
231231
pub type InitArrayVec<T, const N: usize> = GenericVec<T, [T; N]>;
232232
/// An slice backed vector backed by initialized memory
@@ -492,7 +492,7 @@ impl<T, B, A> TypeVec<T, B, A> {
492492
}
493493
}
494494

495-
#[cfg(feature = "nightly")]
495+
#[cfg(any(doc, feature = "nightly"))]
496496
#[cfg_attr(doc, doc(cfg(feature = "nightly")))]
497497
impl<T, const N: usize> ArrayVec<T, N> {
498498
/// Create a new full `ArrayVec`
@@ -542,28 +542,28 @@ impl<T> HeapVec<T> {
542542
}
543543
}
544544

545-
#[cfg(all(feature = "nightly", feature = "alloc"))]
545+
#[cfg(any(doc, all(feature = "nightly", feature = "alloc")))]
546546
#[cfg_attr(doc, doc(cfg(all(feature = "nightly", feature = "alloc"))))]
547547
impl<T, A: std::alloc::AllocRef> HeapVec<T, A> {
548548
/// Create a new empty `HeapVec` with the given allocator
549549
pub fn with_alloc(alloc: A) -> Self { Self::with_storage(raw::Heap::with_alloc(alloc)) }
550550
}
551551

552-
#[cfg(not(feature = "nightly"))]
552+
#[cfg(any(doc, not(feature = "nightly")))]
553553
impl<'a, T> SliceVec<'a, T> {
554554
/// Create a new empty `SliceVec`
555555
pub fn new(slice: &'a mut [MaybeUninit<T>]) -> Self { Self::with_storage(raw::UninitSlice::from_mut(slice)) }
556556
}
557557

558-
#[cfg(feature = "nightly")]
558+
#[cfg(any(doc, feature = "nightly"))]
559559
impl<'a, T> SliceVec<'a, T> {
560560
/// Create a new empty `SliceVec`
561561
///
562562
/// Note: this is only const with the `nightly` feature enabled
563563
pub const fn new(slice: &'a mut [MaybeUninit<T>]) -> Self { Self::with_storage(raw::UninitSlice::from_mut(slice)) }
564564
}
565565

566-
#[cfg(not(feature = "nightly"))]
566+
#[cfg(any(doc, not(feature = "nightly")))]
567567
impl<'a, T: Copy> InitSliceVec<'a, T> {
568568
/// Create a new full `InitSliceVec`
569569
pub fn new(storage: &'a mut [T]) -> Self {
@@ -986,7 +986,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
986986
/// # Panic
987987
///
988988
/// May panic or reallocate if the collection has less than N elements remaining
989-
#[cfg(feature = "nightly")]
989+
#[cfg(any(doc, feature = "nightly"))]
990990
pub fn push_array<const N: usize>(&mut self, value: [T; N]) -> &mut [T; N] {
991991
self.reserve(N);
992992

@@ -1032,7 +1032,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
10321032
///
10331033
/// * May panic or reallocate if the collection has less than N elements remaining
10341034
/// * Panics if index > len.
1035-
#[cfg(feature = "nightly")]
1035+
#[cfg(any(doc, feature = "nightly"))]
10361036
pub fn insert_array<const N: usize>(&mut self, index: usize, value: [T; N]) -> &mut [T; N] {
10371037
#[cold]
10381038
#[inline(never)]
@@ -1083,7 +1083,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
10831083
/// # Panics
10841084
///
10851085
/// Panics if the collection contains less than `N` elements in it
1086-
#[cfg(feature = "nightly")]
1086+
#[cfg(any(doc, feature = "nightly"))]
10871087
pub fn pop_array<const N: usize>(&mut self) -> [T; N] {
10881088
#[cold]
10891089
#[inline(never)]
@@ -1130,7 +1130,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
11301130
/// # Panics
11311131
///
11321132
/// Panics if `index` is out of bounds or if `index + N > len()`
1133-
#[cfg(feature = "nightly")]
1133+
#[cfg(any(doc, feature = "nightly"))]
11341134
pub fn remove_array<const N: usize>(&mut self, index: usize) -> [T; N] {
11351135
#[cold]
11361136
#[inline(never)]
@@ -1199,7 +1199,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
11991199
/// to hold `N` elements.
12001200
///
12011201
/// Guaranteed to not panic/abort/allocate
1202-
#[cfg(feature = "nightly")]
1202+
#[cfg(any(doc, feature = "nightly"))]
12031203
pub fn try_push_array<const N: usize>(&mut self, value: [T; N]) -> Result<&mut [T; N], [T; N]> {
12041204
if self.remaining_capacity() < N {
12051205
Err(value)
@@ -1234,7 +1234,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
12341234
/// to hold `N` elements or index is out of bounds
12351235
///
12361236
/// Guaranteed to not panic/abort/allocate
1237-
#[cfg(feature = "nightly")]
1237+
#[cfg(any(doc, feature = "nightly"))]
12381238
pub fn try_insert_array<const N: usize>(&mut self, index: usize, value: [T; N]) -> Result<&mut [T; N], [T; N]> {
12391239
if self.capacity().wrapping_sub(self.len()) < N || index > self.len() {
12401240
Err(value)
@@ -1266,7 +1266,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
12661266
/// Returns `None` if the collection is has less than N elements
12671267
///
12681268
/// Guaranteed to not panic/abort/allocate
1269-
#[cfg(feature = "nightly")]
1269+
#[cfg(any(doc, feature = "nightly"))]
12701270
pub fn try_pop_array<const N: usize>(&mut self) -> Option<[T; N]> {
12711271
if self.is_empty() {
12721272
None
@@ -1300,7 +1300,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
13001300
/// or `index` is out of bounds.
13011301
///
13021302
/// Guaranteed to not panic/abort/allocate
1303-
#[cfg(feature = "nightly")]
1303+
#[cfg(any(doc, feature = "nightly"))]
13041304
pub fn try_remove_array<const N: usize>(&mut self, index: usize) -> Option<[T; N]> {
13051305
if self.len() < index || self.len().wrapping_sub(index) < N {
13061306
None
@@ -1366,7 +1366,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
13661366
/// # Safety
13671367
///
13681368
/// the collection's remaining capacity must be at least N
1369-
#[cfg(feature = "nightly")]
1369+
#[cfg(any(doc, feature = "nightly"))]
13701370
pub unsafe fn push_array_unchecked<const N: usize>(&mut self, value: [T; N]) -> &mut [T; N] {
13711371
match S::CONST_CAPACITY {
13721372
Some(n) if n < N => {
@@ -1422,7 +1422,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
14221422
///
14231423
/// * the collection's remaining capacity must be at least N
14241424
/// * hte index must be in bounds
1425-
#[cfg(feature = "nightly")]
1425+
#[cfg(any(doc, feature = "nightly"))]
14261426
pub unsafe fn insert_array_unchecked<const N: usize>(&mut self, index: usize, value: [T; N]) -> &mut [T; N] {
14271427
match S::CONST_CAPACITY {
14281428
Some(n) if n < N => {
@@ -1481,7 +1481,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
14811481
/// # Safety
14821482
///
14831483
/// The collection must contain at least `N` elements in it
1484-
#[cfg(feature = "nightly")]
1484+
#[cfg(any(doc, feature = "nightly"))]
14851485
pub unsafe fn pop_array_unchecked<const N: usize>(&mut self) -> [T; N] {
14861486
match S::CONST_CAPACITY {
14871487
Some(n) if n < N => panic!("Tried to remove {} elements from a {} capacity vector!", N, n),
@@ -1546,7 +1546,7 @@ impl<T, S: ?Sized + Storage<T>> GenericVec<T, S> {
15461546
///
15471547
/// the collection must contain at least N elements, and
15481548
/// index must be in bounds
1549-
#[cfg(feature = "nightly")]
1549+
#[cfg(any(doc, feature = "nightly"))]
15501550
pub unsafe fn remove_array_unchecked<const N: usize>(&mut self, index: usize) -> [T; N] {
15511551
match S::CONST_CAPACITY {
15521552
Some(n) if n < N => panic!("Tried to remove {} elements from a {} capacity vector!", N, n),

src/raw.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
use std::boxed::Box;
55

66
mod array;
7-
#[cfg(feature = "alloc")]
7+
#[cfg(any(doc, feature = "alloc"))]
88
mod heap;
99
mod slice;
1010
mod uninit;
1111
mod zero_sized;
1212

1313
mod capacity;
1414

15-
#[cfg(feature = "alloc")]
15+
#[cfg(any(doc, feature = "alloc"))]
1616
pub use heap::Heap;
1717

1818
pub use slice::UninitSlice;
@@ -106,9 +106,9 @@ unsafe impl<T, S: ?Sized + Storage<T>> Storage<T> for &mut S {
106106
fn try_reserve(&mut self, new_capacity: usize) -> bool { S::try_reserve(self, new_capacity) }
107107
}
108108

109-
#[cfg(feature = "alloc")]
109+
#[cfg(any(doc, feature = "alloc"))]
110110
unsafe impl<T, S: ?Sized + StorageInit<T>> StorageInit<T> for Box<S> {}
111-
#[cfg(feature = "alloc")]
111+
#[cfg(any(doc, feature = "alloc"))]
112112
unsafe impl<T, S: ?Sized + Storage<T>> Storage<T> for Box<S> {
113113
#[doc(hidden)]
114114
const CONST_CAPACITY: Option<usize> = S::CONST_CAPACITY;
@@ -126,7 +126,7 @@ unsafe impl<T, S: ?Sized + Storage<T>> Storage<T> for Box<S> {
126126
fn try_reserve(&mut self, new_capacity: usize) -> bool { S::try_reserve(self, new_capacity) }
127127
}
128128

129-
#[cfg(feature = "alloc")]
129+
#[cfg(any(doc, feature = "alloc"))]
130130
unsafe impl<T, S: ?Sized + StorageWithCapacity<T>> StorageWithCapacity<T> for Box<S> {
131131
#[inline(always)]
132132
fn with_capacity(capacity: usize) -> Self { Box::new(S::with_capacity(capacity)) }

src/raw/heap.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ macro_rules! doc_heap {
77
}
88
}
99

10-
#[cfg(feature = "nightly")]
10+
#[cfg(any(doc, feature = "nightly"))]
1111
mod nightly;
12-
#[cfg(not(feature = "nightly"))]
12+
#[cfg(not(any(doc, feature = "nightly")))]
1313
mod stable;
1414

15-
#[cfg(feature = "nightly")]
15+
#[cfg(any(doc, feature = "nightly"))]
1616
pub use nightly::Heap;
17-
#[cfg(not(feature = "nightly"))]
17+
#[cfg(not(any(doc, feature = "nightly")))]
1818
pub use stable::Heap;
1919

2020
const INIT_ALLOC_CAPACITY: usize = 4;

src/raw/heap/nightly.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use core::{
1010
};
1111
use std::alloc::handle_alloc_error;
1212

13-
#[cfg(feature = "nightly")]
1413
use std::alloc::{AllocRef, Global};
1514

1615
doc_heap! {

0 commit comments

Comments
 (0)