parallelsystems / bit-struct Goto Github PK
View Code? Open in Web Editor NEWergonomic bitfields in Rust
ergonomic bitfields in Rust
I imagine the repository link (https://github.com/parallel-systems/bit-struct
) is not supposed to have that one hyphen in the user name.
u{x}!
macrostechnically 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.
The readme contains a full example of use case, it's would be nice to have an compiled example of what item are generated in the doc, like https://docs.rs/snafu/0.6.10/snafu/guide/examples/basic/index.html for example.
This is more easy to understand what macro do for the user.
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)
Good afternoon! I've been writing something heavily using this library but I came across a roadblock.
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.
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 GetSet
s, 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.
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.
Both lead me to https://github.com/parallel-systems/bit-struct but the correct url is https://github.com/parallelsystems/bit-struct/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.