Comments (6)
The bitflags! { struct Qux: u32 { .. } } case currently just uses a newtype to make plain #[derive()]s work
That's what bitflags 1 was doing. bitflags 2 is different in that matter, which is the reason for this issue in the first place. Specifically, it uses a newtype of an internal type that #[derive()]
s can't be applied to.
from bitflags.
Hi @glandium 👋
It looks like you're using the impl-style bitflags!
because you also need support for other custom derives? It seems like there's more we can do to make that pattern nicer. Perhaps a proc-macro library that leveraged the Flags
trait to offer its own custom-derives for Debug
etc:
#[derive(bitflags::Debug, Foo, Bar)]
pub struct Qux(u32);
bitflags! {
impl Qux: u32 {
...
}
}
from bitflags.
It wouldn't need to be a proc macro, it should be possible to make this work:
#[derive(....)]
pub struct Qux(u32);
bitflags! {
#[derive(Debug)}
impl Qux: u32 {
...
}
}
// produces the same Debug impl that this would produce:
// bitflags! {
// #[derive(Debug)]
// struct Qux: u32 {...}
// }
from bitflags.
Both would work, although the proc-macro would feel better because it groups the derive in a single place, but I can understand that it's more stuff to compile.
from bitflags.
My preference would be for a proc-macro, starting in an external library with the option to include in bitflags
through a feature, but would never want to pull any proc-macros in to bitflags
by-default. The reason I'd like to avoid macro_rules!
for this is the macro logic in bitflags!
is already quite complicated, and I'd like to avoid introducing any magic attributes wherever possible. The bitflags! { struct Qux: u32 { .. } }
case currently just uses a newtype to make plain #[derive()]
s work, since many custom-derives treat newtypes differently.
from bitflags.
bitflags
1.x
used a struct like struct Flags { bits: u32 }
, so you could #[derive]
many things, but they would be based on that un-semantic u32
so probably not what you actually want to implement. bitflags
2.x
uses a newtype like struct Flags(FlagsInner)
where FlagsInner
manually implements traits semantically so you can add #[derive]
s on Flags
and get something closer to what you want to implement, but has the (significant) drawback that only traits implemented by FlagsInner
can be #[derive]
'd on Flags
.
from bitflags.
Related Issues (20)
- Problems deriving serde after upgrading HOT 2
- Treatment of unknown bits in operators is inconsistent HOT 18
- Inconsistent debug output for flag with no bits HOT 4
- SWC - Update to 2.3.x causes incorrect output HOT 9
- Flagging supply-chain security issues HOT 3
- Match expression question HOT 2
- messes with dependent crates! HOT 3
- Documenting bitflags: how to get documentation for the generated bitflags HOT 4
- clippy::iter_without_into_iter HOT 3
- Feature guard `parser`? HOT 4
- Static member variable on the impl? HOT 2
- [Feature Request] `repr(packed)` for internal bits types HOT 2
- [Feature Request] Smaller internal types with non-breaking size increases HOT 3
- [Feature Request] Serialize as struct of bools HOT 2
- [Feature Request] Make Flags trait methods public HOT 1
- Enforce uniqueness of flags HOT 4
- FR: Please make operators cosnt. bitwise or operator `|` is not const HOT 3
- Allow specifying attributes in `impl` mode HOT 1
- `cargo doc` doesn't check for broken links in bitflags documentation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bitflags.