File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ use std:: borrow:: Cow ;
11
12
use std:: cmp:: Ordering :: { Equal , Greater , Less } ;
12
13
use std:: str:: from_utf8;
13
14
@@ -1267,6 +1268,16 @@ fn test_box_slice_clone() {
1267
1268
assert_eq ! ( data, data2) ;
1268
1269
}
1269
1270
1271
+ #[ test]
1272
+ fn test_cow_from ( ) {
1273
+ let borrowed = "borrowed" ;
1274
+ let owned = String :: from ( "owned" ) ;
1275
+ match ( Cow :: from ( owned. clone ( ) ) , Cow :: from ( borrowed) ) {
1276
+ ( Cow :: Owned ( o) , Cow :: Borrowed ( b) ) => assert ! ( o == owned && b == borrowed) ,
1277
+ _ => panic ! ( "invalid `Cow::from`" ) ,
1278
+ }
1279
+ }
1280
+
1270
1281
mod pattern {
1271
1282
use std:: str:: pattern:: Pattern ;
1272
1283
use std:: str:: pattern:: { Searcher , ReverseSearcher } ;
Original file line number Diff line number Diff line change 8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ use std:: borrow:: Cow ;
11
12
use std:: iter:: { FromIterator , repeat} ;
12
13
use std:: mem:: size_of;
13
14
@@ -466,6 +467,16 @@ fn test_into_iter_count() {
466
467
assert_eq ! ( vec![ 1 , 2 , 3 ] . into_iter( ) . count( ) , 3 ) ;
467
468
}
468
469
470
+ #[ test]
471
+ fn test_cow_from ( ) {
472
+ let borrowed: & [ _ ] = & [ "borrowed" , "(slice)" ] ;
473
+ let owned = vec ! [ "owned" , "(vec)" ] ;
474
+ match ( Cow :: from ( owned. clone ( ) ) , Cow :: from ( borrowed) ) {
475
+ ( Cow :: Owned ( o) , Cow :: Borrowed ( b) ) => assert ! ( o == owned && b == borrowed) ,
476
+ _ => panic ! ( "invalid `Cow::from`" ) ,
477
+ }
478
+ }
479
+
469
480
#[ bench]
470
481
fn bench_new ( b : & mut Bencher ) {
471
482
b. iter ( || {
You can’t perform that action at this time.
0 commit comments