Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BitVec::from_iter has unexpected len #276

Open
balopat opened this issue Jul 30, 2024 · 0 comments
Open

BitVec::from_iter has unexpected len #276

balopat opened this issue Jul 30, 2024 · 0 comments

Comments

@balopat
Copy link

balopat commented Jul 30, 2024

Maybe I'm doing something wrong, but the code below is failing. I expected from_iter to result in a BitVec with the same len() as the number of iterated elements.

use bitvec::prelude::*;

fn main() {
    let bool_vec = vec![false, true];
    let bv: BitVec<usize, Lsb0> =
        BitVec::from_iter(
            bool_vec
                .iter()
                .map(|b| if *b { 1 as usize } else { 0 as usize }),
        );
    assert_eq!(bitvec![0, 1], bv);
}

failure:

thread 'main' panicked at src/main.rs:11:5:
assertion `left == right` failed
  left: BitVec<usize, bitvec::order::Lsb0> { addr: 0x5594c6db8bc0, head: 000000, bits: 2, capacity: 64 } [0, 1]
 right: BitVec<usize, bitvec::order::Lsb0> { addr: 0x5594c6db8ba0, head: 000000, bits: 128, capacity: 128 } [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
stack backtrace:
   0: rust_begin_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:72:14
   2: core::panicking::assert_failed_inner
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:409:17
   3: core::panicking::assert_failed
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:364:5
   4: temp::main
             at ./src/main.rs:11:5
   5: core::ops::function::FnOnce::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant