Struct rill_protocol::timed_frame::TimedFrame [−][src]
pub struct TimedFrame<T> { /* fields omitted */ }
Implementations
Methods from Deref<Target = VecDeque<TimedEvent<T>>>
Provides a reference to the element at the given index.
Element at index 0 is the front of the queue.
Examples
use std::collections::VecDeque; let mut buf = VecDeque::new(); buf.push_back(3); buf.push_back(4); buf.push_back(5); assert_eq!(buf.get(1), Some(&4));
Returns the number of elements the VecDeque
can hold without
reallocating.
Examples
use std::collections::VecDeque; let buf: VecDeque<i32> = VecDeque::with_capacity(10); assert!(buf.capacity() >= 10);
🔬 This is a nightly-only experimental API. (allocator_api
)
allocator_api
)Returns a reference to the underlying allocator.
Returns a front-to-back iterator.
Examples
use std::collections::VecDeque; let mut buf = VecDeque::new(); buf.push_back(5); buf.push_back(3); buf.push_back(4); let b: &[_] = &[&5, &3, &4]; let c: Vec<&i32> = buf.iter().collect(); assert_eq!(&c[..], b);
Returns a pair of slices which contain, in order, the contents of the
VecDeque
.
If make_contiguous
was previously called, all elements of the
VecDeque
will be in the first slice and the second slice will be empty.
Examples
use std::collections::VecDeque; let mut vector = VecDeque::new(); vector.push_back(0); vector.push_back(1); vector.push_back(2); assert_eq!(vector.as_slices(), (&[0, 1, 2][..], &[][..])); vector.push_front(10); vector.push_front(9); assert_eq!(vector.as_slices(), (&[9, 10][..], &[0, 1, 2][..]));
Returns the number of elements in the VecDeque
.
Examples
use std::collections::VecDeque; let mut v = VecDeque::new(); assert_eq!(v.len(), 0); v.push_back(1); assert_eq!(v.len(), 1);
Returns true
if the VecDeque
is empty.
Examples
use std::collections::VecDeque; let mut v = VecDeque::new(); assert!(v.is_empty()); v.push_front(1); assert!(!v.is_empty());
Creates an iterator that covers the specified range in the VecDeque
.
Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.
Examples
use std::collections::VecDeque; let v: VecDeque<_> = vec![1, 2, 3].into_iter().collect(); let range = v.range(2..).copied().collect::<VecDeque<_>>(); assert_eq!(range, [3]); // A full range covers all contents let all = v.range(..); assert_eq!(all.len(), 3);
Returns true
if the VecDeque
contains an element equal to the
given value.
Examples
use std::collections::VecDeque; let mut vector: VecDeque<u32> = VecDeque::new(); vector.push_back(0); vector.push_back(1); assert_eq!(vector.contains(&1), true); assert_eq!(vector.contains(&10), false);
Provides a reference to the front element, or None
if the VecDeque
is
empty.
Examples
use std::collections::VecDeque; let mut d = VecDeque::new(); assert_eq!(d.front(), None); d.push_back(1); d.push_back(2); assert_eq!(d.front(), Some(&1));
Provides a reference to the back element, or None
if the VecDeque
is
empty.
Examples
use std::collections::VecDeque; let mut d = VecDeque::new(); assert_eq!(d.back(), None); d.push_back(1); d.push_back(2); assert_eq!(d.back(), Some(&2));
Binary searches this sorted VecDeque
for a given element.
If the value is found then Result::Ok
is returned, containing the
index of the matching element. If there are multiple matches, then any
one of the matches could be returned. If the value is not found then
Result::Err
is returned, containing the index where a matching
element could be inserted while maintaining sorted order.
See also binary_search_by
, binary_search_by_key
, and partition_point
.
Examples
Looks up a series of four elements. The first is found, with a
uniquely determined position; the second and third are not
found; the fourth could match any position in [1, 4]
.
use std::collections::VecDeque; let deque: VecDeque<_> = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into(); assert_eq!(deque.binary_search(&13), Ok(9)); assert_eq!(deque.binary_search(&4), Err(7)); assert_eq!(deque.binary_search(&100), Err(13)); let r = deque.binary_search(&1); assert!(matches!(r, Ok(1..=4)));
If you want to insert an item to a sorted VecDeque
, while maintaining
sort order:
use std::collections::VecDeque; let mut deque: VecDeque<_> = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into(); let num = 42; let idx = deque.binary_search(&num).unwrap_or_else(|x| x); deque.insert(idx, num); assert_eq!(deque, &[0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]);
Binary searches this sorted VecDeque
with a comparator function.
The comparator function should implement an order consistent
with the sort order of the underlying VecDeque
, returning an
order code that indicates whether its argument is Less
,
Equal
or Greater
than the desired target.
If the value is found then Result::Ok
is returned, containing the
index of the matching element. If there are multiple matches, then any
one of the matches could be returned. If the value is not found then
Result::Err
is returned, containing the index where a matching
element could be inserted while maintaining sorted order.
See also binary_search
, binary_search_by_key
, and partition_point
.
Examples
Looks up a series of four elements. The first is found, with a
uniquely determined position; the second and third are not
found; the fourth could match any position in [1, 4]
.
use std::collections::VecDeque; let deque: VecDeque<_> = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into(); assert_eq!(deque.binary_search_by(|x| x.cmp(&13)), Ok(9)); assert_eq!(deque.binary_search_by(|x| x.cmp(&4)), Err(7)); assert_eq!(deque.binary_search_by(|x| x.cmp(&100)), Err(13)); let r = deque.binary_search_by(|x| x.cmp(&1)); assert!(matches!(r, Ok(1..=4)));
Binary searches this sorted VecDeque
with a key extraction function.
Assumes that the VecDeque
is sorted by the key, for instance with
make_contiguous().sort_by_key()
using the same key extraction function.
If the value is found then Result::Ok
is returned, containing the
index of the matching element. If there are multiple matches, then any
one of the matches could be returned. If the value is not found then
Result::Err
is returned, containing the index where a matching
element could be inserted while maintaining sorted order.
See also binary_search
, binary_search_by
, and partition_point
.
Examples
Looks up a series of four elements in a slice of pairs sorted by
their second elements. The first is found, with a uniquely
determined position; the second and third are not found; the
fourth could match any position in [1, 4]
.
use std::collections::VecDeque; let deque: VecDeque<_> = vec![(0, 0), (2, 1), (4, 1), (5, 1), (3, 1), (1, 2), (2, 3), (4, 5), (5, 8), (3, 13), (1, 21), (2, 34), (4, 55)].into(); assert_eq!(deque.binary_search_by_key(&13, |&(a, b)| b), Ok(9)); assert_eq!(deque.binary_search_by_key(&4, |&(a, b)| b), Err(7)); assert_eq!(deque.binary_search_by_key(&100, |&(a, b)| b), Err(13)); let r = deque.binary_search_by_key(&1, |&(a, b)| b); assert!(matches!(r, Ok(1..=4)));
Returns the index of the partition point according to the given predicate (the index of the first element of the second partition).
The deque is assumed to be partitioned according to the given predicate. This means that all elements for which the predicate returns true are at the start of the deque and all elements for which the predicate returns false are at the end. For example, [7, 15, 3, 5, 4, 12, 6] is a partitioned under the predicate x % 2 != 0 (all odd numbers are at the start, all even at the end).
If this deque is not partitioned, the returned result is unspecified and meaningless, as this method performs a kind of binary search.
See also binary_search
, binary_search_by
, and binary_search_by_key
.
Examples
use std::collections::VecDeque; let deque: VecDeque<_> = vec![1, 2, 3, 3, 5, 6, 7].into(); let i = deque.partition_point(|&x| x < 5); assert_eq!(i, 4); assert!(deque.iter().take(i).all(|&x| x < 5)); assert!(deque.iter().skip(i).all(|&x| !(x < 5)));
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for TimedFrame<T> where
T: RefUnwindSafe,
impl<T> Send for TimedFrame<T> where
T: Send,
impl<T> Sync for TimedFrame<T> where
T: Sync,
impl<T> Unpin for TimedFrame<T> where
T: Unpin,
impl<T> UnwindSafe for TimedFrame<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more