Code Monkey home page Code Monkey logo

Comments (2)

Robbepop avatar Robbepop commented on July 17, 2024

Hi!
Thank you for the bug report and the test case - that helps a lot.
I ll look into it. :)

from modular-bitfield.

Robbepop avatar Robbepop commented on July 17, 2024

I slightly modified the test case to:

use modular_bitfield::prelude::*;

#[derive(BitfieldSpecifier, Debug, PartialEq, Copy, Clone)]
pub enum Mode {
    A = 0b00,
    B = 0b01,
    C = 0b10,
    D = 0b11,
}

#[bitfield]
#[derive(Debug)]
pub struct StatFlag {
    x: bool,
    y: bool,
    z: B4,
    #[bits = 2]
    mode: Mode,
}

fn main() {
    let mut flag = StatFlag::new();

    assert_eq!(flag.get_x(), false);
    assert_eq!(flag.get_y(), false);
    assert_eq!(flag.get_z(), 0);
    assert_eq!(flag.get_mode(), Mode::A);

    let new_mode = Mode::B;

    flag.set_mode(new_mode);
    assert_eq!(flag.get_mode(), new_mode);

    flag.set_x(true);
    assert_eq!(flag.get_x(), true);
    assert_eq!(flag.get_mode(), new_mode);

    flag.set_y(true);
    assert_eq!(flag.get_y(), true);
    assert_eq!(flag.get_mode(), new_mode);

    flag.set_z(0b11);
    assert_eq!(flag.get_z(), 0b11);
    assert_eq!(flag.get_mode(), new_mode);
}

The problem seems to be that the mode field is always reset to 0.

from modular-bitfield.

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.