Debian Codegraph @

tests/deref_index.rs

raw symbols SCIP
1 /*
2 Copyright ⓒ 2015 rust-custom-derive contributors.
3
4 Licensed under the MIT license (see LICENSE or <http://opensource.org
5 /licenses/MIT>) or the Apache License, Version 2.0 (see LICENSE of
6 <http://www.apache.org/licenses/LICENSE-2.0>), at your option. All
7 files in the project carrying such notice may not be copied, modified,
8 or distributed except according to those terms.
9 */
10 #[macro_use] extern crate custom_derive;
11 #[macro_use] extern crate newtype_derive;
12
13 custom_derive! {
14 #[derive(Clone, Eq, PartialEq, Debug,
15 NewtypeFrom,
16 NewtypeDeref, NewtypeDerefMut,
17 NewtypeIndex(usize), NewtypeIndexMut(usize)
18 )]
19 pub struct Dummy(Vec<i32>);
20 }
21
22 #[test]
23 fn test_deref_index() {
24 let mut a = Dummy::from(vec![1, 2, 3]);
25
26 assert_eq!(a.len(), 3);
27 a.push(4);
28 assert_eq!(&**a, &[1, 2, 3, 4][..]);
29
30 assert_eq!(a[1], 2);
31 a[2] = 5;
32 assert_eq!(a[2], 5);
33 }