Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9d9b55c
make invalid_type_param_default lint show up in cargo future-compat r…
RalfJung Jul 15, 2024
bda31d1
built-in derive: remove BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE hack …
RalfJung Jul 18, 2024
9b165a1
Implement cursors for `BTreeSet`
kmicklas Jul 28, 2024
bbeff8c
set `force_recompile: true` if library is modified
onur-ozkan Jul 30, 2024
6fcc630
update download-rustc documentation
onur-ozkan Jul 30, 2024
0204762
Share `UnorderedKeyError` with `BTReeMap` for set API
kmicklas Aug 1, 2024
4560770
Fix some uses of "map" instead of "set" in `BTreeSet` cursor API docs
kmicklas Aug 1, 2024
cbdc377
Introduce `Cursor`/`CursorMut`/`CursorMutKey` thrichotomy for `BTreeS…
kmicklas Aug 1, 2024
0bc501e
Fix mutability in doc tests for `BTreeSet` cursors
kmicklas Aug 1, 2024
8497800
Add test for updating enum discriminant through pointer
clubby789 Aug 1, 2024
9e5c9c1
tests: add regression test for incorrect "builtin attribute is checke…
jieyouxu Aug 4, 2024
9d0eaa2
check_attr: cover multi-segment attributes on specific check arms
jieyouxu Aug 4, 2024
cc61dc8
Rollup merge of #127655 - RalfJung:invalid_type_param_default, r=comp…
matthiaskrgr Aug 5, 2024
d10f2b3
Rollup merge of #127907 - RalfJung:byte_slice_in_packed_struct_with_d…
matthiaskrgr Aug 5, 2024
f6c8b7a
Rollup merge of #127974 - onur-ozkan:force-std-builds, r=Mark-Simulacrum
matthiaskrgr Aug 5, 2024
e4367ce
Rollup merge of #128309 - kmicklas:btreeset-cursor, r=Amanieu
matthiaskrgr Aug 5, 2024
3c8b259
Rollup merge of #128500 - clubby789:122600-test, r=Mark-Simulacrum
matthiaskrgr Aug 5, 2024
2048007
Rollup merge of #128623 - jieyouxu:check-attr-ice, r=nnethercote
matthiaskrgr Aug 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Share UnorderedKeyError with BTReeMap for set API
  • Loading branch information
kmicklas committed Aug 1, 2024
commit 020476296b1aa60f79c2f671c48542afe99cc428
36 changes: 7 additions & 29 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::vec::Vec;
use core::borrow::Borrow;
use core::cmp::Ordering::{self, Equal, Greater, Less};
use core::cmp::{max, min};
use core::error::Error;
use core::fmt::{self, Debug};
use core::hash::{Hash, Hasher};
use core::iter::{FusedIterator, Peekable};
Expand Down Expand Up @@ -2177,11 +2176,11 @@ impl<'a, T: Ord, A: Allocator + Clone> CursorMut<'a, T, A> {
///
/// If the inserted element is not greater than the element before the
/// cursor (if any), or if it not less than the element after the cursor (if
/// any), then an [`UnorderedError`] is returned since this would
/// any), then an [`UnorderedKeyError`] is returned since this would
/// invalidate the [`Ord`] invariant between the elements of the set.
#[unstable(feature = "btree_cursors", issue = "107540")]
pub fn insert_after(&mut self, value: T) -> Result<(), UnorderedError> {
self.inner.insert_after(value, SetValZST).map_err(UnorderedError::from_map_error)
pub fn insert_after(&mut self, value: T) -> Result<(), UnorderedKeyError> {
self.inner.insert_after(value, SetValZST)
}

/// Inserts a new element into the set in the gap that the
Expand All @@ -2192,11 +2191,11 @@ impl<'a, T: Ord, A: Allocator + Clone> CursorMut<'a, T, A> {
///
/// If the inserted element is not greater than the element before the
/// cursor (if any), or if it not less than the element after the cursor (if
/// any), then an [`UnorderedError`] is returned since this would
/// any), then an [`UnorderedKeyError`] is returned since this would
/// invalidate the [`Ord`] invariant between the elements of the set.
#[unstable(feature = "btree_cursors", issue = "107540")]
pub fn insert_before(&mut self, value: T) -> Result<(), UnorderedError> {
self.inner.insert_before(value, SetValZST).map_err(UnorderedError::from_map_error)
pub fn insert_before(&mut self, value: T) -> Result<(), UnorderedKeyError> {
self.inner.insert_before(value, SetValZST)
}

/// Removes the next element from the `BTreeSet`.
Expand All @@ -2218,29 +2217,8 @@ impl<'a, T: Ord, A: Allocator + Clone> CursorMut<'a, T, A> {
}
}

/// Error type returned by [`CursorMut::insert_before`] and
/// [`CursorMut::insert_after`] if the element being inserted is not properly
/// ordered with regards to adjacent elements.
#[derive(Clone, PartialEq, Eq, Debug)]
#[unstable(feature = "btree_cursors", issue = "107540")]
pub struct UnorderedError {}

impl UnorderedError {
fn from_map_error(error: super::map::UnorderedKeyError) -> Self {
let super::map::UnorderedKeyError {} = error;
Self {}
}
}

#[unstable(feature = "btree_cursors", issue = "107540")]
impl fmt::Display for UnorderedError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "value is not properly ordered relative to neighbors")
}
}

#[unstable(feature = "btree_cursors", issue = "107540")]
impl Error for UnorderedError {}
pub use super::map::UnorderedKeyError;

#[cfg(test)]
mod tests;