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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/// The `TakeSlice` trait for Rust enables treating slices and `Vec` instances interchangeably.
///
/// # Examples
///
/// `take_slice` can take in both slices and vectors.
/// If it takes in a slice, no copying is needed unless `take` is called.
/// ```
/// use take_ref::TakeSlice;
///
/// fn take_slice(value: impl TakeSlice<i64>) {
/// assert_eq!(value.as_slice(), [1, 2, 3]); // `as_slice` references the value in place.
/// assert_eq!(value.as_slice(), [1, 2, 3]); // `as_slice` can be repeated until `take`.
/// assert_eq!(value.take(), [1, 2, 3]); // `take` consumes the value.
/// }
///
/// let numbers = vec!(1, 2, 3);
/// take_slice(numbers.as_slice());
/// take_slice(numbers);
/// ```
///
/// ## Disallowed Operations
///
/// `slice_taken` fails to compile since it attempts to slice `value` after `take` has already consumed it.
/// ```compile_fail
/// fn slice_taken(value: impl take_ref::TakeSlice<i64>) {
/// value.take(); // `take` consumes the value.
/// value.slice(); // This call is disallowed since the value has been consumed.
/// }
/// ```
///
/// `take_taken` fails to compile since it attempts to `take` `value` after `take` has already consumed it.
/// ```compile_fail
/// fn take_taken(value: impl take_ref::TakeSlice<i64>) {
/// value.take(); // `take` consumes the value.
/// value.take(); // This call is disallowed since the value has been consumed.
/// }
/// ```