Sha256: fff83dc39d30e75e8e611991f9c5399188a1aad23a6462dbca2c8b62655cfedb

Contents?: true

Size: 644 Bytes

Versions: 30

Compression:

Stored size: 644 Bytes

Contents

use crate::lib::*;

pub fn from_bounds<I>(iter: &I) -> Option<usize>
where
    I: Iterator,
{
    helper(iter.size_hint())
}

#[cfg(any(feature = "std", feature = "alloc"))]
pub fn cautious<Element>(hint: Option<usize>) -> usize {
    const MAX_PREALLOC_BYTES: usize = 1024 * 1024;

    if mem::size_of::<Element>() == 0 {
        0
    } else {
        cmp::min(
            hint.unwrap_or(0),
            MAX_PREALLOC_BYTES / mem::size_of::<Element>(),
        )
    }
}

fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {
    match bounds {
        (lower, Some(upper)) if lower == upper => Some(upper),
        _ => None,
    }
}

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/serde-1.0.217/src/de/size_hint.rs
wasmtime-28.0.0 ./ext/cargo-vendor/serde-1.0.217/src/de/size_hint.rs
wasmtime-27.0.0 ./ext/cargo-vendor/serde-1.0.215/src/de/size_hint.rs
wasmtime-26.0.0 ./ext/cargo-vendor/serde-1.0.213/src/de/size_hint.rs
wasmtime-25.0.2 ./ext/cargo-vendor/serde-1.0.208/src/de/size_hint.rs
wasmtime-25.0.1 ./ext/cargo-vendor/serde-1.0.208/src/de/size_hint.rs
wasmtime-25.0.0 ./ext/cargo-vendor/serde-1.0.208/src/de/size_hint.rs
wasmtime-24.0.0 ./ext/cargo-vendor/serde-1.0.208/src/de/size_hint.rs
wasmtime-23.0.2 ./ext/cargo-vendor/serde-1.0.195/src/de/size_hint.rs
wasmtime-22.0.0 ./ext/cargo-vendor/serde-1.0.195/src/de/size_hint.rs
wasmtime-21.0.1 ./ext/cargo-vendor/serde-1.0.195/src/de/size_hint.rs
wasmtime-20.0.2 ./ext/cargo-vendor/serde-1.0.195/src/de/size_hint.rs
wasmtime-20.0.0 ./ext/cargo-vendor/serde-1.0.195/src/de/size_hint.rs
wasmtime-18.0.3 ./ext/cargo-vendor/serde-1.0.195/src/de/size_hint.rs
wasmtime-17.0.1 ./ext/cargo-vendor/serde-1.0.195/src/de/size_hint.rs
wasmtime-17.0.0 ./ext/cargo-vendor/serde-1.0.195/src/de/size_hint.rs
wasmtime-16.0.0 ./ext/cargo-vendor/serde-1.0.195/src/de/size_hint.rs
wasmtime-15.0.1 ./ext/cargo-vendor/serde-1.0.195/src/de/size_hint.rs
wasmtime-15.0.0 ./ext/cargo-vendor/serde-1.0.195/src/de/size_hint.rs
wasmtime-14.0.4 ./ext/cargo-vendor/serde-1.0.190/src/de/size_hint.rs