Skip to content

Commit 43cf7a5

Browse files
authored
Merge pull request #6 from ava57r/push-front
Added push_front function
2 parents 5f8e808 + f90263e commit 43cf7a5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,31 @@ impl<T> Vc<T> {
13181318
}
13191319
}
13201320

1321+
/// Inserts an element at the front of the queue, shifting all elements with indices
1322+
/// greater than or equal to `index` towards the back.
1323+
///
1324+
/// # Panics
1325+
///
1326+
/// Panics if `index` is greater than `Vc`'s length
1327+
///
1328+
/// # Examples
1329+
///
1330+
/// ```
1331+
/// use atone::Vc;
1332+
///
1333+
/// let mut vec_deque = Vc::new();
1334+
/// vec_deque.push_front('a');
1335+
/// vec_deque.push_front('b');
1336+
/// vec_deque.push_front('c');
1337+
/// assert_eq!(vec_deque, vec!['c', 'b', 'a']);
1338+
///
1339+
/// vec_deque.insert(1, 'd');
1340+
/// assert_eq!(vec_deque, vec!['c', 'd', 'b', 'a']);
1341+
/// ```
1342+
pub fn push_front(&mut self, value: T) {
1343+
self.insert(0, value);
1344+
}
1345+
13211346
/// Removes and returns the element at `index` from the `Vc`.
13221347
/// Whichever end is closer to the removal point will be moved to make
13231348
/// room, and all the affected elements will be moved to new positions.

0 commit comments

Comments
 (0)