1 use core::cell::RefCell;
2 use core::hash::{Hash, Hasher};
3 use core::mem;
4 use core::ops::{Bound, RangeBounds};
5 
6 use crate::traits::Sealed;
7 
8 pub trait RefCell_v1_35<T>: Sealed<RefCell<T>> {
replace_with<F: FnOnce(&mut T) -> T>(&self, f: F) -> T9     fn replace_with<F: FnOnce(&mut T) -> T>(&self, f: F) -> T;
10 }
11 
12 impl<T> RefCell_v1_35<T> for RefCell<T> {
13     #[inline]
replace_with<F: FnOnce(&mut T) -> T>(&self, f: F) -> T14     fn replace_with<F: FnOnce(&mut T) -> T>(&self, f: F) -> T {
15         let mut_borrow = &mut *self.borrow_mut();
16         let replacement = f(mut_borrow);
17         mem::replace(mut_borrow, replacement)
18     }
19 }
20 
21 pub trait Option_v1_35<'a, T: Copy + 'a>: Sealed<Option<&'a T>> {
copied(self) -> Option<T>22     fn copied(self) -> Option<T>;
23 }
24 
25 impl<'a, T: Copy + 'a> Option_v1_35<'a, T> for Option<&'a T> {
copied(self) -> Option<T>26     fn copied(self) -> Option<T> {
27         self.map(|&t| t)
28     }
29 }
30 
hash<T: ?Sized, S: Hasher>(hashee: *const T, into: &mut S)31 pub fn hash<T: ?Sized, S: Hasher>(hashee: *const T, into: &mut S) {
32     hashee.hash(into);
33 }
34 
35 pub trait RangeBounds_v1_35<T>: RangeBounds<T> {
contains<U>(&self, item: &U) -> bool where T: PartialOrd<U>, U: ?Sized + PartialOrd<T>36     fn contains<U>(&self, item: &U) -> bool
37     where
38         T: PartialOrd<U>,
39         U: ?Sized + PartialOrd<T>;
40 }
41 
42 impl<T: PartialOrd<T>, RB: RangeBounds<T>> RangeBounds_v1_35<T> for RB {
contains<U>(&self, item: &U) -> bool where T: PartialOrd<U>, U: ?Sized + PartialOrd<T>,43     fn contains<U>(&self, item: &U) -> bool
44     where
45         T: PartialOrd<U>,
46         U: ?Sized + PartialOrd<T>,
47     {
48         contains(self, item)
49     }
50 }
51 
contains<T, U>(range: &impl RangeBounds<T>, item: &U) -> bool where T: ?Sized + PartialOrd<U>, U: ?Sized + PartialOrd<T>,52 fn contains<T, U>(range: &impl RangeBounds<T>, item: &U) -> bool
53 where
54     T: ?Sized + PartialOrd<U>,
55     U: ?Sized + PartialOrd<T>,
56 {
57     (match range.start_bound() {
58         Bound::Included(ref start) => *start <= item,
59         Bound::Excluded(ref start) => *start < item,
60         Bound::Unbounded => true,
61     }) && (match range.end_bound() {
62         Bound::Included(ref end) => item <= *end,
63         Bound::Excluded(ref end) => item < *end,
64         Bound::Unbounded => true,
65     })
66 }
67