summaryrefslogtreecommitdiffstats
path: root/third_party/rust/rental/tests/string.rs
blob: 9f6c7ea9da081f1f3768b5e1c3d9859beb41d27f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#[macro_use]
extern crate rental;


rental! {
	pub mod rent_string {
		#[rental(deref_suffix)]
		pub struct OwnedStr {
			buffer: String,
			slice: &'buffer str,
			slice_2: &'slice str,
		}
	}
}


#[test]
fn new() {
	let buf = "Hello, World!".to_string();
	let _ = rent_string::OwnedStr::new(buf, |slice| slice, |slice, _| slice);
}


#[test]
fn read() {
	let buf = "Hello, World!".to_string();
	let rbuf = rent_string::OwnedStr::new(buf, |slice| slice, |slice, _| slice);

	assert_eq!(&*rbuf, "Hello, World!");
}