kuikuitage

  博客园  ::  :: 新随笔  :: 联系 ::  :: 管理
pub loss_probes: [usize; packet::EPOCH_COUNT],

pub fn cwnd_available(&self) -> usize {
        // 发送探测数据包时忽略cwnd。
        // Ignore cwnd when sending probe packets.
        if self.loss_probes.iter().any(|&x| x > 0) {
            return std::usize::MAX;
        }
self.congestion_window.saturating_sub(self.bytes_in_flight));
        self.congestion_window.saturating_sub(self.bytes_in_flight)
    }

迭代器测试,参考官网说明 method.any

fn any(&mut self, f: F) -> bool

where
Self: Sized,
F: FnMut(Self::Item) -> bool,

Tests if any element of the iterator matches a predicate.

any() takes a closure that returns true or false. It applies this closure to each element of the iterator, and if any of them return true, then so does any(). If they all return false, it returns false.

any() is short-circuiting; in other words, it will stop processing as soon as it finds a true, given that no matter what else happens, the result will also be true.

An empty iterator returns false.

Examples

Basic usage:

let a = [1, 2, 3];

assert!(a.iter().any(|&x| x > 0));

assert!(!a.iter().any(|&x| x > 5));

Stopping at the first true:

let a = [1, 2, 3];

let mut iter = a.iter();

assert!(iter.any(|&x| x != 2));

// we can still use `iter`, as there are more elements.
assert_eq!(iter.next(), Some(&2));

Print file, function and line number for debugging

there are a few macros: line!, column! and file!

You can find a bunch of other useful macros in the standard library documentation 182 (look at the bottom of the page)

Macro std::line
Macro std::column
Macro std::file
posted on 2020-08-04 02:01  kuikuitage  阅读(177)  评论(0编辑  收藏  举报