summaryrefslogtreecommitdiffstats
path: root/vendor/indexmap/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/indexmap/src/lib.rs')
-rw-r--r--vendor/indexmap/src/lib.rs112
1 files changed, 98 insertions, 14 deletions
diff --git a/vendor/indexmap/src/lib.rs b/vendor/indexmap/src/lib.rs
index 6e9493612..8939d261a 100644
--- a/vendor/indexmap/src/lib.rs
+++ b/vendor/indexmap/src/lib.rs
@@ -14,7 +14,7 @@
//! [`IndexSet`]: set/struct.IndexSet.html
//!
//!
-//! ### Feature Highlights
+//! ### Highlights
//!
//! [`IndexMap`] and [`IndexSet`] are drop-in compatible with the std `HashMap`
//! and `HashSet`, but they also have some features of note:
@@ -26,6 +26,34 @@
//! - The [`MutableKeys`][map::MutableKeys] trait, which gives opt-in mutable
//! access to hash map keys.
//!
+//! ### Feature Flags
+//!
+//! To reduce the amount of compiled code in the crate by default, certain
+//! features are gated behind [feature flags]. These allow you to opt in to (or
+//! out of) functionality. Below is a list of the features available in this
+//! crate.
+//!
+//! * `std`: Enables features which require the Rust standard library. For more
+//! information see the section on [`no_std`].
+//! * `rayon`: Enables parallel iteration and other parallel methods.
+//! * `serde`: Adds implementations for [`Serialize`] and [`Deserialize`]
+//! to [`IndexMap`] and [`IndexSet`]. Alternative implementations for
+//! (de)serializing [`IndexMap`] as an ordered sequence are available in the
+//! [`map::serde_seq`] module.
+//! * `arbitrary`: Adds implementations for the [`arbitrary::Arbitrary`] trait
+//! to [`IndexMap`] and [`IndexSet`].
+//! * `quickcheck`: Adds implementations for the [`quickcheck::Arbitrary`] trait
+//! to [`IndexMap`] and [`IndexSet`].
+//!
+//! _Note: only the `std` feature is enabled by default._
+//!
+//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
+//! [`no_std`]: #no-standard-library-targets
+//! [`Serialize`]: `::serde::Serialize`
+//! [`Deserialize`]: `::serde::Deserialize`
+//! [`arbitrary::Arbitrary`]: `::arbitrary::Arbitrary`
+//! [`quickcheck::Arbitrary`]: `::quickcheck::Arbitrary`
+//!
//! ### Alternate Hashers
//!
//! [`IndexMap`] and [`IndexSet`] have a default hasher type `S = RandomState`,
@@ -53,21 +81,20 @@
//!
//! ### Rust Version
//!
-//! This version of indexmap requires Rust 1.56 or later.
+//! This version of indexmap requires Rust 1.64 or later.
//!
-//! The indexmap 1.x release series will use a carefully considered version
-//! upgrade policy, where in a later 1.x version, we will raise the minimum
+//! The indexmap 2.x release series will use a carefully considered version
+//! upgrade policy, where in a later 2.x version, we will raise the minimum
//! required Rust version.
//!
//! ## No Standard Library Targets
//!
-//! This crate supports being built without `std`, requiring
-//! `alloc` instead. This is enabled automatically when it is detected that
-//! `std` is not available. There is no crate feature to enable/disable to
-//! trigger this. It can be tested by building for a std-less target.
+//! This crate supports being built without `std`, requiring `alloc` instead.
+//! This is chosen by disabling the default "std" cargo feature, by adding
+//! `default-features = false` to your dependency specification.
//!
//! - Creating maps and sets using [`new`][IndexMap::new] and
-//! [`with_capacity`][IndexMap::with_capacity] is unavailable without `std`.
+//! [`with_capacity`][IndexMap::with_capacity] is unavailable without `std`.
//! Use methods [`IndexMap::default`][def],
//! [`with_hasher`][IndexMap::with_hasher],
//! [`with_capacity_and_hasher`][IndexMap::with_capacity_and_hasher] instead.
@@ -77,9 +104,11 @@
//!
//! [def]: map/struct.IndexMap.html#impl-Default
+#![cfg_attr(docsrs, feature(doc_cfg))]
+
extern crate alloc;
-#[cfg(has_std)]
+#[cfg(feature = "std")]
#[macro_use]
extern crate std;
@@ -88,12 +117,10 @@ use alloc::vec::{self, Vec};
mod arbitrary;
#[macro_use]
mod macros;
-mod equivalent;
mod mutable_keys;
#[cfg(feature = "serde")]
+#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
mod serde;
-#[cfg(feature = "serde")]
-pub mod serde_seq;
mod util;
pub mod map;
@@ -102,14 +129,15 @@ pub mod set;
// Placed after `map` and `set` so new `rayon` methods on the types
// are documented after the "normal" methods.
#[cfg(feature = "rayon")]
+#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
mod rayon;
#[cfg(feature = "rustc-rayon")]
mod rustc;
-pub use crate::equivalent::Equivalent;
pub use crate::map::IndexMap;
pub use crate::set::IndexSet;
+pub use equivalent::Equivalent;
// shared private items
@@ -192,3 +220,59 @@ trait Entries {
where
F: FnOnce(&mut [Self::Entry]);
}
+
+/// The error type for `try_reserve` methods.
+#[derive(Clone, PartialEq, Eq, Debug)]
+pub struct TryReserveError {
+ kind: TryReserveErrorKind,
+}
+
+#[derive(Clone, PartialEq, Eq, Debug)]
+enum TryReserveErrorKind {
+ // The standard library's kind is currently opaque to us, otherwise we could unify this.
+ Std(alloc::collections::TryReserveError),
+ CapacityOverflow,
+ AllocError { layout: alloc::alloc::Layout },
+}
+
+// These are not `From` so we don't expose them in our public API.
+impl TryReserveError {
+ fn from_alloc(error: alloc::collections::TryReserveError) -> Self {
+ Self {
+ kind: TryReserveErrorKind::Std(error),
+ }
+ }
+
+ fn from_hashbrown(error: hashbrown::TryReserveError) -> Self {
+ Self {
+ kind: match error {
+ hashbrown::TryReserveError::CapacityOverflow => {
+ TryReserveErrorKind::CapacityOverflow
+ }
+ hashbrown::TryReserveError::AllocError { layout } => {
+ TryReserveErrorKind::AllocError { layout }
+ }
+ },
+ }
+ }
+}
+
+impl core::fmt::Display for TryReserveError {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ let reason = match &self.kind {
+ TryReserveErrorKind::Std(e) => return core::fmt::Display::fmt(e, f),
+ TryReserveErrorKind::CapacityOverflow => {
+ " because the computed capacity exceeded the collection's maximum"
+ }
+ TryReserveErrorKind::AllocError { .. } => {
+ " because the memory allocator returned an error"
+ }
+ };
+ f.write_str("memory allocation failed")?;
+ f.write_str(reason)
+ }
+}
+
+#[cfg(feature = "std")]
+#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
+impl std::error::Error for TryReserveError {}