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
/// Truncates elements from the **end** of a vector, dropping the specified number of items in place.
///
/// # Type Parameters
/// - `T`: The element type contained in the vector. No specific traits are required.
///
/// # Arguments
/// - `values`: A mutable reference to the vector from which elements will be removed.
/// - `no_of_elements_to_drop`: The number of elements to remove from the end of the vector.
///
/// # Returns
/// This function returns no value. It modifies the input vector in place.
///
/// # Behavior
/// - Removes the last `no_of_elements_to_drop` elements from the vector.
/// - If `no_of_elements_to_drop` is `0`, the vector is left unchanged.
/// - If `no_of_elements_to_drop` is greater than or equal to the vector’s length, the vector is cleared.
///
/// # Performance
/// - ✅ In-place operation with **O(1)** time complexity.
/// - 🚫 No reallocation or element cloning occurs.
/// - ⚡ Very fast: uses `.truncate()` internally, which adjusts the vector’s length without touching memory.
///
/// # Examples
///
/// ### ✂️ Remove the last few elements
/// ```
/// use pencil_box::array::drop_end::drop_end;
///
/// let mut data = vec![10, 20, 30, 40];
/// drop_end(&mut data, 2);
/// assert_eq!(data, vec![10, 20]);
/// ```
///
/// ### 🛑 Drop zero elements (no change)
/// ```
/// let mut data = vec![1, 2, 3];
/// drop_end(&mut data, 0);
/// assert_eq!(data, vec![1, 2, 3]);
/// ```
///
/// ### 💥 Drop more than the vector contains (clears the vector)
/// ```
/// let mut data = vec![5, 6];
/// drop_end(&mut data, 10);
/// assert!(data.is_empty());
/// ```
///
/// ### 🔤 Use with strings or owned types
/// ```
/// let mut data = vec!["apple".to_string(), "banana".to_string(), "cherry".to_string()];
/// drop_end(&mut data, 1);
/// assert_eq!(data, vec!["apple", "banana"]);
/// ```
///
/// ### 📭 Start from an empty vector
/// ```
/// let mut data: Vec<i32> = vec![];
/// drop_end(&mut data, 3);
/// assert!(data.is_empty());
/// ```