GithubHelp home page GithubHelp logo

bit-struct's People

Contributors

andrewgazelka avatar jarredallen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bit-struct's Issues

100% test coverage

  • need to run several tests in macros to cover all signed/unsiged variants

fix UB with core::mem::transmute

technically according to docs what we are doing is UB, but given our invariants perhaps it actually isn't (all tests pass at least on MacOS)... and it seems to work on cortex processors.
This should be pretty easy to fix by using core::ptr instead.

Failure to build without also explicitly adding serde as dependency

Every invocation of bit_struct! and enums! fails because of this:

error[E0463]: can't find crate for `serde`
  --> src/leaf6.rs:6:1
   |
6  | / bit_struct! {
7  | |
8  | |     pub struct ThermalFeatures(u32) {
9  | |         DTS: bool,
...  |
27 | |     }
28 | | }
   | |_^ can't find crate
   |
   = note: this error originates in the derive macro `$crate::serde::Deserialize` which comes from the expansion of the macro `bit_struct` (in Nightly builds, run with -Z macro-backtrace for more info)

Unable to use bit structs in a read-only context.

Good afternoon! I've been writing something heavily using this library but I came across a roadblock.

Problem

The way GetSet are created means that I need mutability of a bit struct to be able to read from it, which is not necessary nor possible in some cases.

Example

use bit_struct::*;

bit_struct! {
	// Useless struct for demonstration purposes
	pub struct Halfling(u8) {
		first_half: u4,
		second_half: u4
	}
}

impl Display for Halfling {
	// note immutability of self
	fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
		writeln!(f, "The halves together make {}", self.first_half.get().value() + self.second_half.get().value())
	}
}

This will not compile because .first_half() and .second_half() take &mut self to make their GetSets, which the signature of Display::fmt doesn't permit. In this use case I don't need to modify the Halfling at all and can't, but it insists it must be mutable.

Solution?

I understand why GetSet needs to be constructed with a mutable reference, so I propose a Get or similarly named struct with read-only privileges that will work in this context. How that would work, I'm not sure.

By convention it would make sense to change all generated field GetSet functions to mut_[field name] and make the existing ones return Get structs instead, but this would break everything wholesale. How would you prefer to implement this? I would be willing to do the legwork in a PR.

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.