@@ -207,6 +207,47 @@ impl<B: ?Sized + ToOwned> Clone for Cow<'_, B> {
207
207
}
208
208
209
209
impl < B : ?Sized + ToOwned > Cow < ' _ , B > {
210
+ /// Returns true if the data is borrowed, i.e. if `to_mut` would require additional work.
211
+ ///
212
+ /// # Examples
213
+ ///
214
+ /// ```
215
+ /// #![feature(cow_is_borrowed)]
216
+ /// use std::borrow::Cow;
217
+ ///
218
+ /// let cow = Cow::Borrowed("moo");
219
+ /// assert!(cow.is_borrowed());
220
+ ///
221
+ /// let bull: Cow<'_, str> = Cow::Owned("...moo?".to_string());
222
+ /// assert!(!bull.is_borrowed());
223
+ /// ```
224
+ #[ unstable( feature = "cow_is_borrowed" , issue = "65143" ) ]
225
+ pub fn is_borrowed ( & self ) -> bool {
226
+ match * self {
227
+ Borrowed ( _) => true ,
228
+ Owned ( _) => false ,
229
+ }
230
+ }
231
+
232
+ /// Returns true if the data is owned, i.e. if `to_mut` would be a no-op.
233
+ ///
234
+ /// # Examples
235
+ ///
236
+ /// ```
237
+ /// #![feature(cow_is_borrowed)]
238
+ /// use std::borrow::Cow;
239
+ ///
240
+ /// let cow: Cow<'_, str> = Cow::Owned("moo".to_string());
241
+ /// assert!(cow.is_owned());
242
+ ///
243
+ /// let bull = Cow::Borrowed("...moo?");
244
+ /// assert!(!bull.is_owned());
245
+ /// ```
246
+ #[ unstable( feature = "cow_is_borrowed" , issue = "65143" ) ]
247
+ pub fn is_owned ( & self ) -> bool {
248
+ !self . is_borrowed ( )
249
+ }
250
+
210
251
/// Acquires a mutable reference to the owned form of the data.
211
252
///
212
253
/// Clones the data if it is not already owned.
0 commit comments