]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/send_str_hashmap.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use std
::collections
::HashMap
;
14 use std
::borrow
::Cow
::Borrowed
as B
;
15 use std
::borrow
::Cow
::Owned
as O
;
17 type SendStr
= Cow
<'
static, str>;
20 let mut map
: HashMap
<SendStr
, usize> = HashMap
::new();
21 assert
!(map
.insert(B("foo"), 42).is_none());
22 assert
!(map
.insert(O("foo".to_string()), 42).is_some());
23 assert
!(map
.insert(B("foo"), 42).is_some());
24 assert
!(map
.insert(O("foo".to_string()), 42).is_some());
26 assert
!(map
.insert(B("foo"), 43).is_some());
27 assert
!(map
.insert(O("foo".to_string()), 44).is_some());
28 assert
!(map
.insert(B("foo"), 45).is_some());
29 assert
!(map
.insert(O("foo".to_string()), 46).is_some());
33 assert_eq
!(map
.get(&O("foo".to_string())), Some(&v
));
34 assert_eq
!(map
.get(&B("foo")), Some(&v
));
36 let (a
, b
, c
, d
) = (50, 51, 52, 53);
38 assert
!(map
.insert(B("abc"), a
).is_none());
39 assert
!(map
.insert(O("bcd".to_string()), b
).is_none());
40 assert
!(map
.insert(B("cde"), c
).is_none());
41 assert
!(map
.insert(O("def".to_string()), d
).is_none());
43 assert
!(map
.insert(B("abc"), a
).is_some());
44 assert
!(map
.insert(O("bcd".to_string()), b
).is_some());
45 assert
!(map
.insert(B("cde"), c
).is_some());
46 assert
!(map
.insert(O("def".to_string()), d
).is_some());
48 assert
!(map
.insert(O("abc".to_string()), a
).is_some());
49 assert
!(map
.insert(B("bcd"), b
).is_some());
50 assert
!(map
.insert(O("cde".to_string()), c
).is_some());
51 assert
!(map
.insert(B("def"), d
).is_some());
53 assert_eq
!(map
.get("abc"), Some(&a
));
54 assert_eq
!(map
.get("bcd"), Some(&b
));
55 assert_eq
!(map
.get("cde"), Some(&c
));
56 assert_eq
!(map
.get("def"), Some(&d
));
58 assert_eq
!(map
.get(&B("abc")), Some(&a
));
59 assert_eq
!(map
.get(&B("bcd")), Some(&b
));
60 assert_eq
!(map
.get(&B("cde")), Some(&c
));
61 assert_eq
!(map
.get(&B("def")), Some(&d
));