Skip to content

Commit

Permalink
Make cow_is_borrowed methods const
Browse files Browse the repository at this point in the history
Constify the following methods of `alloc::borrow::Cow`:
 - `is_borrowed`
 - `is_owned`

These methods are still unstable under `cow_is_borrowed`.
Possible because of rust-lang#49146 (Allow if and match in constants).

Tracking issue: rust-lang#65143
  • Loading branch information
CDirkx committed Aug 31, 2020
1 parent 36b0d7e commit af24bdb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/alloc/src/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
/// assert!(!bull.is_borrowed());
/// ```
#[unstable(feature = "cow_is_borrowed", issue = "65143")]
pub fn is_borrowed(&self) -> bool {
pub const fn is_borrowed(&self) -> bool {
match *self {
Borrowed(_) => true,
Owned(_) => false,
Expand All @@ -239,7 +239,7 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
/// assert!(!bull.is_owned());
/// ```
#[unstable(feature = "cow_is_borrowed", issue = "65143")]
pub fn is_owned(&self) -> bool {
pub const fn is_owned(&self) -> bool {
!self.is_borrowed()
}

Expand Down

0 comments on commit af24bdb

Please sign in to comment.