Giter Club home page Giter Club logo

mju-bits's Introduction

mju-bits

#[no_std] implementation of typed bitfield access for u8, u16, u32, u64 and usize.

Usage

use mju_bits::*;

struct RegisterMarker;
type Register = Storage<RegisterMarker, u32>;
type RegisterAll = BitField<Register, U0, U31>;
type RegisterFieldA = BitField<Register, U0, U7>;
type RegisterFieldB = BitField<Register, U8, U24>;

let mut reg = Register::new();
reg.set::<RegisterFieldA>(0x56);
reg.set::<RegisterFieldB>(0x1234);
assert_eq!(reg.get::<RegisterAll>(), 0x00123456);

The Storage type ensures that a field may only be used with its corresponding storage.

For example, this won't compile:

use mju_bits::*;

struct FooMarker;
type Foo = Storage<FooMarker, u8>;
type FooField = BitField<Foo, U0, U1>;

struct BarMarker;
type Bar = Storage<BarMarker, u8>;

let bar = Bar::new();

// Compiler error: FooField can not be used with Bar storage.
bar.get::<FooField>();

Roadmap

  • BitFields spanning multiple primitive types
  • Iterable sequences of BitFields, supporting functional protocol definition
  • Implementation compatible with generic consts on nightly
  • Improve types so larger bitfields can be supported - 128-bit fields break typenum
  • Others?

Changelog

  • 0.3.0 - Removal of B0..B63 aliases to avoid confusion with typenum::B0 and typenum::B1
  • 0.2.0 - Documentation and cleanup
  • 0.1.0 - Initial release

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.