Skip to content

Commit f7c958c

Browse files
Last few updates before 0.11.0
1 parent 985036a commit f7c958c

File tree

9 files changed

+44
-32
lines changed

9 files changed

+44
-32
lines changed

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ status = "actively-developed"
1818
[badges.appveyor]
1919
repository = "slightlyoutofphase/staticvec"
2020

21+
[package.metadata.docs.rs]
22+
features = ["std", "serde"]
23+
rustdoc-args = ["--cfg","docs_rs"]
24+
2125
[profile.release]
2226
opt-level = 3
2327
debug = false
@@ -55,8 +59,6 @@ incremental = false
5559

5660
[features]
5761
std = []
58-
serde_support = ["serde"]
59-
serde_json_support = ["serde_json"]
6062
default = ["std"]
6163

6264
[[test]]
@@ -108,7 +110,7 @@ required-features = ["std"]
108110
[[example]]
109111
name = "serde_support_demo"
110112
path = "demo/serde_support_demo.rs"
111-
required-features = ["std", "serde_support", "serde_json_support"]
113+
required-features = ["std", "serde", "serde_json"]
112114

113115
[dependencies]
114116
serde = { optional = true, version = "1.0", features = ["derive"] }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Fully `#![no_std]` compatible (with almost no loss of functionality) by setting
1616
`default-features = false` for the `staticvec` dependency in your `Cargo.toml`.
1717

1818
Optional support for serialization and deserialization of the `StaticVec` struct
19-
via `serde` is available by activating the `serde_support` crate feature.
19+
via `serde` is available by activating the `serde` crate feature.
2020

2121
`StaticVec` also implements both `Deref` and `DerefMut` to `[T]`, meaning that all existing slice
2222
methods are accessible through instances of it and that references to it can be used in contexts

src/heap/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::mem::swap;
22

3-
#[cfg(feature = "serde_support")]
3+
#[cfg(feature = "serde")]
44
use serde::{Deserialize, Serialize};
55

66
use self::heap_helpers::StaticHeapHole;
@@ -98,7 +98,7 @@ mod heap_trait_impls;
9898
/// [pop]: #method.pop
9999
/// [peek]: #method.peek
100100
/// [peek\_mut]: #method.peek_mut
101-
#[cfg_attr(feature = "serde_support", derive(Deserialize, Serialize))]
101+
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
102102
pub struct StaticHeap<T, const N: usize> {
103103
pub(crate) data: StaticVec<T, N>,
104104
}

src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ pub mod utils;
110110

111111
/// A [`Vec`](alloc::vec::Vec)-like struct (mostly directly API-compatible where it can be)
112112
/// implemented with const generics around an array of fixed `N` capacity.
113+
///
114+
/// Please note that while rustdoc does currently correctly render inherent `const fn` method
115+
/// signatures, the same is not true of `const` trait implementation method signatures, so at this
116+
/// time it's recommended that you refer directly to the source code of this crate if unsure of
117+
/// whether a given trait has been implemented as `const` in conjunction with the `const_trait_impl`
118+
/// feature.
113119
pub struct StaticVec<T, const N: usize> {
114120
// We create this field in an uninitialized state, and write to it element-wise as needed via
115121
// pointer methods. At no time should the regular `assume_init` function *ever* be called through
@@ -1398,8 +1404,8 @@ impl<T, const N: usize> StaticVec<T, N> {
13981404
/// );
13991405
/// ```
14001406
#[inline]
1401-
pub fn quicksorted_unstable(&self) -> Self
1402-
where T: Copy + PartialOrd {
1407+
pub const fn quicksorted_unstable(&self) -> Self
1408+
where T: Copy + ~const PartialOrd {
14031409
let length = self.length;
14041410
if length < 2 {
14051411
// StaticVec uses specialization to have an optimized verson of `Clone` for copy types.
@@ -1433,8 +1439,8 @@ impl<T, const N: usize> StaticVec<T, N> {
14331439
/// // values simply not being sorted quite as you'd hoped.
14341440
/// ```
14351441
#[inline]
1436-
pub fn quicksort_unstable(&mut self)
1437-
where T: Copy + PartialOrd {
1442+
pub const fn quicksort_unstable(&mut self)
1443+
where T: Copy + ~const PartialOrd {
14381444
let length = self.length;
14391445
if length < 2 {
14401446
return;
@@ -2140,7 +2146,7 @@ impl<T, const N: usize> StaticVec<T, N> {
21402146
/// assert_eq!(v2, [2, 3]);
21412147
/// ```
21422148
#[inline]
2143-
pub fn split_off(&mut self, at: usize) -> Self {
2149+
pub const fn split_off(&mut self, at: usize) -> Self {
21442150
let old_length = self.length;
21452151
assert!(
21462152
at <= old_length,

src/macros.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ macro_rules! staticvec {
8686
/// contexts.
8787
///
8888
/// For example, this would give a compile-time error:
89-
/// ```
90-
/// // const S5: StaticString<1> = staticstring!("ABCDEFG", 1);
89+
/// ```compile_fail
90+
/// const S5: StaticString<1> = staticstring!("ABCDEFG", 1);
9191
/// ```
9292
/// As would the following:
93-
/// ```
94-
/// // let s6 = staticstring!("🤔🤔🤔🤔🤔🤔", 0);
93+
/// ```compile_fail
94+
/// let s6 = staticstring!("🤔🤔🤔🤔🤔🤔", 0);
9595
/// ```
9696
#[macro_export]
9797
#[rustfmt::skip]

src/string/string_errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl Display for StringError {
6969
}
7070

7171
#[cfg(feature = "std")]
72+
#[doc(cfg(feature = "std"))]
7273
impl std::error::Error for StringError {}
7374

7475
impl const From<DecodeUtf16Error> for StringError {

src/string/string_trait_impls.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::StaticVec;
1515
#[cfg(feature = "std")]
1616
use alloc::string::String;
1717

18-
#[cfg(feature = "serde_support")]
18+
#[cfg(feature = "serde")]
1919
use serde::{de::Deserializer, ser::Serializer, Deserialize, Serialize};
2020

2121
impl<const N: usize> Add<&str> for StaticString<N> {
@@ -165,8 +165,8 @@ impl<const N: usize> From<StaticVec<u8, N>> for StaticString<N> {
165165
}
166166
}
167167

168-
/// **Note:** this is only available when the `std` crate feature is enabled.
169168
#[cfg(feature = "std")]
169+
#[doc(cfg(feature = "std"))]
170170
impl<const N: usize> From<String> for StaticString<N> {
171171
#[inline(always)]
172172
fn from(string: String) -> Self {
@@ -337,8 +337,8 @@ impl<const N: usize> PartialEq<&str> for StaticString<N> {
337337
}
338338
}
339339

340-
/// **Note:** this is only available when the `std` crate feature is enabled.
341340
#[cfg(feature = "std")]
341+
#[doc(cfg(feature = "std"))]
342342
impl<const N: usize> PartialEq<String> for StaticString<N> {
343343
#[inline(always)]
344344
fn eq(&self, other: &String) -> bool {
@@ -367,8 +367,8 @@ impl<const N: usize> PartialOrd<&str> for StaticString<N> {
367367
}
368368
}
369369

370-
/// **Note:** this is only available when the `std` crate feature is enabled.
371370
#[cfg(feature = "std")]
371+
#[doc(cfg(feature = "std"))]
372372
impl<const N: usize> PartialOrd<String> for StaticString<N> {
373373
#[inline(always)]
374374
fn partial_cmp(&self, other: &String) -> Option<Ordering> {
@@ -388,15 +388,17 @@ impl<const N: usize> Write for StaticString<N> {
388388
}
389389
}
390390

391-
#[cfg(feature = "serde_support")]
391+
#[cfg(feature = "serde")]
392+
#[doc(cfg(feature = "serde"))]
392393
impl<'de, const N: usize> Deserialize<'de> for StaticString<N> {
393394
#[inline(always)]
394395
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
395396
<&str>::deserialize(deserializer).map(Self::from_str)
396397
}
397398
}
398399

399-
#[cfg(feature = "serde_support")]
400+
#[cfg(feature = "serde")]
401+
#[doc(cfg(feature = "serde"))]
400402
impl<const N: usize> Serialize for StaticString<N> {
401403
#[inline(always)]
402404
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {

src/trait_impls.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ use alloc::vec::Vec;
3131
#[cfg(feature = "std")]
3232
use std::io::{self, BufRead, IoSlice, IoSliceMut, Read, ReadBuf, Write};
3333

34-
#[cfg(feature = "serde_support")]
34+
#[cfg(feature = "serde")]
3535
use core::marker::PhantomData;
3636

37-
#[cfg(feature = "serde_support")]
37+
#[cfg(feature = "serde")]
3838
use serde::{
3939
de::{SeqAccess, Visitor},
4040
Deserialize, Deserializer, Serialize, Serializer,
@@ -456,8 +456,8 @@ impl<const N: usize> From<StaticString<N>> for StaticVec<u8, N> {
456456
}
457457
}
458458

459-
/// **Note:** this is only available when the `std` crate feature is enabled.
460459
#[cfg(feature = "std")]
460+
#[doc(cfg(feature = "std"))]
461461
impl<T, const N: usize> From<Vec<T>> for StaticVec<T, N> {
462462
/// Functionally equivalent to [`from_vec`](crate::StaticVec::from_vec).
463463
#[inline(always)]
@@ -693,9 +693,9 @@ impl<T, const N: usize> const IndexMut<RangeToInclusive<usize>> for StaticVec<T,
693693
}
694694
}
695695

696-
/// **Note:** this is only available when the `std` crate feature is enabled.
697696
#[allow(clippy::from_over_into)]
698697
#[cfg(feature = "std")]
698+
#[doc(cfg(feature = "std"))]
699699
impl<T, const N: usize> Into<Vec<T>> for StaticVec<T, N> {
700700
/// Functionally equivalent to [`into_vec`](crate::StaticVec::into_vec).
701701
#[inline(always)]
@@ -794,9 +794,8 @@ impl_partial_ord_with_as_slice_against_slice!(&mut [T1], StaticVec<T2, N>);
794794

795795
/// Read from a StaticVec. This implementation operates by copying bytes into the destination
796796
/// buffers, then shifting the remaining bytes over.
797-
///
798-
/// **Note:** this is only available when the `std` crate feature is enabled.
799797
#[cfg(feature = "std")]
798+
#[doc(cfg(feature = "std"))]
800799
impl<const N: usize> Read for StaticVec<u8, N> {
801800
#[inline]
802801
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
@@ -901,8 +900,8 @@ impl<const N: usize> Read for StaticVec<u8, N> {
901900
}
902901
}
903902

904-
/// **Note:** this is only available when the `std` crate feature is enabled.
905903
#[cfg(feature = "std")]
904+
#[doc(cfg(feature = "std"))]
906905
impl<const N: usize> Write for StaticVec<u8, N> {
907906
#[inline]
908907
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
@@ -942,8 +941,8 @@ impl<const N: usize> Write for StaticVec<u8, N> {
942941
}
943942
}
944943

945-
/// **Note:** this is only available when the `std` crate feature is enabled.
946944
#[cfg(feature = "std")]
945+
#[doc(cfg(feature = "std"))]
947946
impl<const N: usize> BufRead for StaticVec<u8, N> {
948947
#[inline(always)]
949948
fn fill_buf(&mut self) -> io::Result<&[u8]> {
@@ -956,7 +955,8 @@ impl<const N: usize> BufRead for StaticVec<u8, N> {
956955
}
957956
}
958957

959-
#[cfg(feature = "serde_support")]
958+
#[cfg(feature = "serde")]
959+
#[doc(cfg(feature = "serde"))]
960960
impl<'de, T, const N: usize> Deserialize<'de> for StaticVec<T, N>
961961
where T: Deserialize<'de>
962962
{
@@ -993,7 +993,8 @@ where T: Deserialize<'de>
993993
}
994994
}
995995

996-
#[cfg(feature = "serde_support")]
996+
#[cfg(feature = "serde")]
997+
#[doc(cfg(feature = "serde"))]
997998
impl<T, const N: usize> Serialize for StaticVec<T, N>
998999
where T: Serialize
9991000
{

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub(crate) fn partial_compare<T1, T2: PartialOrd<T1>>(
126126
/// A simple quicksort function for internal use, called in
127127
/// ['quicksorted_unstable`](crate::StaticVec::quicksorted_unstable).
128128
#[inline]
129-
pub(crate) fn quicksort_internal<T: Copy + PartialOrd>(
129+
pub(crate) const fn quicksort_internal<T: Copy + ~const PartialOrd>(
130130
values: *mut T,
131131
mut low: isize,
132132
mut high: isize,

0 commit comments

Comments
 (0)