Giter Club home page Giter Club logo

Comments (2)

myrrlyn avatar myrrlyn commented on August 15, 2024 2

Hi! I apologize for the long delay; I have had a very stressful winter and have not had the time or energy to check this repository in a timely manner. I'm trying to catch up now.


Okay, so, bitslice[index] already produces a bool; you shouldn't need to change its type. But this is definitely a logic error in funty.

I'll have to fix it in funty 2, since bitvec 1 is going to keep using that. Thank you for bringing it to my attention.

from bitvec.

ntc2 avatar ntc2 commented on August 15, 2024

I just got bit by this, very confusing!

In my case, I was using as_bool() because I'm not familiar with BitVec and some API I'm calling returned BitVec. I wanted to iterate over the bits, so I did .iter(), and then I ended up with a BitRef, and I called as_bool() on that, causing the problem illustrated by the OP.

For completeness here's my minimal test case:

// use bitvec::prelude::*;
let interrogate_lsb = |x: BitVec<_, _>| {
    let lsb_array = x[0];
    let lsb_iter_as_bool = x.iter().next().unwrap().as_bool();
    let lsb_iter_as_u64 = x.iter().next().unwrap().as_u64();
    println!("x: {x:?}");
    println!("x[0]: {lsb_array:?}");
    println!("x.iter().next().unwrap().as_bool(): {lsb_iter_as_bool:?}");
    println!("x.iter().next().unwrap().as_u64(): {lsb_iter_as_u64:?}");
};
let mut bv = bitvec![u8, Lsb0;];
bv.push(false);
interrogate_lsb(bv);
println!();
let mut bv = bitvec![u8, Lsb0;];
bv.push(true);
interrogate_lsb(bv);

which prints

x: BitVec<u8, bitvec::order::Lsb0> { addr: 0x7fc434001f20, head: 000, bits: 1, capacity: 64 } [0]
x[0]: false
x.iter.next().unwrap(): BitRef<u8, bitvec::order::Lsb0> { addr: 0x7fc434001f20, head: 000, bits: 1, bit: false }
x.iter().next().unwrap().as_bool(): true
x.iter().next().unwrap().as_u64(): 0

x: BitVec<u8, bitvec::order::Lsb0> { addr: 0x7fc434001f20, head: 000, bits: 1, capacity: 64 } [1]
x[0]: true
x.iter.next().unwrap(): BitRef<u8, bitvec::order::Lsb0> { addr: 0x7fc434001f20, head: 000, bits: 1, bit: true }
x.iter().next().unwrap().as_bool(): false
x.iter().next().unwrap().as_u64(): 1

from bitvec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.