@@ -674,10 +674,10 @@ pub enum Bound<T> {
674
674
Unbounded,
675
675
}
676
676
677
- #[unstable(feature = "bound_as_ref", issue = "80996")]
678
677
impl<T> Bound<T> {
679
678
/// Converts from `&Bound<T>` to `Bound<&T>`.
680
679
#[inline]
680
+ #[unstable(feature = "bound_as_ref", issue = "80996")]
681
681
pub fn as_ref(&self) -> Bound<&T> {
682
682
match *self {
683
683
Included(ref x) => Included(x),
@@ -688,13 +688,47 @@ impl<T> Bound<T> {
688
688
689
689
/// Converts from `&mut Bound<T>` to `Bound<&T>`.
690
690
#[inline]
691
+ #[unstable(feature = "bound_as_ref", issue = "80996")]
691
692
pub fn as_mut(&mut self) -> Bound<&mut T> {
692
693
match *self {
693
694
Included(ref mut x) => Included(x),
694
695
Excluded(ref mut x) => Excluded(x),
695
696
Unbounded => Unbounded,
696
697
}
697
698
}
699
+
700
+ /// Maps a `Bound<T>` to a `Bound<U>` by applying a function to the contained value (including
701
+ /// both `Included` and `Excluded`), returning a `Bound` of the same kind.
702
+ ///
703
+ /// # Examples
704
+ ///
705
+ /// ```
706
+ /// #![feature(bound_map)]
707
+ /// use std::ops::Bound::*;
708
+ ///
709
+ /// let bound_string = Included("Hello, World!");
710
+ ///
711
+ /// assert_eq!(bound_string.map(|s| s.len()), Included(13));
712
+ /// ```
713
+ ///
714
+ /// ```
715
+ /// #![feature(bound_map)]
716
+ /// use std::ops::Bound;
717
+ /// use Bound::*;
718
+ ///
719
+ /// let unbounded_string: Bound<String> = Unbounded;
720
+ ///
721
+ /// assert_eq!(unbounded_string.map(|s| s.len()), Unbounded);
722
+ /// ```
723
+ #[inline]
724
+ #[unstable(feature = "bound_map", issue = "86026")]
725
+ pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Bound<U> {
726
+ match self {
727
+ Unbounded => Unbounded,
728
+ Included(x) => Included(f(x)),
729
+ Excluded(x) => Excluded(f(x)),
730
+ }
731
+ }
698
732
}
699
733
700
734
impl<T: Clone> Bound<&T> {
0 commit comments