Comments (16)
I pushed the changes to https://github.com/MaikKlein/enumflags/tree/no_std
You can use it like this
enumflags_derive = {path = "../enumflags_derive", default-features=false}
I want to test it a bit more before I merge it with master.
from enumflags.
@aoowweenn Sorry for the delay, I refactored almost everything. The println should be gone now.
from enumflags.
I myself don't do embedded programming but I guess there shouldn't a problem with switching from std
to core
. I'll look into it tomorrow.
from enumflags.
I currently use a vector for the debug output https://github.com/MaikKlein/enumflags/blob/master/enumflags_derive/src/lib.rs#L229
I also want to generalize that behavior so that you can create a flag from a vector of flags, and that you can create a vector of flags from a single flag. I do this to generate a better debug output, eg BitFlags { 0b1111, Flags::[A, B, C, D] }
. But this is quite unnecessary for the debug output, it should be possible to avoid the heap usage here by directly writing to the fmt
instead of collecting into a vector.
I think that it should be possible to feature gate the std usage.
from enumflags.
I took care of removing std-dependent code in my fork, but I need your help with some things:
- At enumflags_derive/src/lib.rs:100
extern crate core
is needed. But if I add it, enumflags breaks when usingstd
. Please take a look at it. - At enumflags_derive/src/lib.rs:168, I commented that
println!
. Really, I don't know why it's there, but I prefer leaving it until I get your opinion. - At enumflags_derive/src/lib.rs:237 there is a function that isn't documented anywhere, but returns a
Vec
and prevent it from being used withoutstd
.
I think these changes are enough. I'll make a (new) PR if I make it work...
from enumflags.
- and 3.: It probably breaks because I still rely on the
std
. I didn't realize that I already had implementedfrom_bitflag
. This is useful if you ever want to use enumflags in a config file. For example
[Input.Jump]
Key = Left
Modifiers = [Shift, Ctrl] // <- enumflags
Which means I need a way to convert from a list of flags into a BitFlags<Flag>
and the other way around, this is essentially what ``from_bitflag` is currently for.
I think we should just feature gate the std usage like here https://github.com/BurntSushi/byteorder/blob/master/src/lib.rs#L53
#[cfg(feature = "std")]
pub fn from_bitflag(bitflag: ::enumflags::BitFlags<#ident>) -> Vec<#ident> {
- This is something that shouldn't be there.
I really need to add some documentation and tests.
from enumflags.
Regarding extern crate core
. I implement something called
pub struct #inner_name(#ty);
which is the inner type of the bitflag. This is necessary because it is not possible to implement code between two crates (enumflags and enumflags_derive are two separate crates).
Currently this inner type is in user space, which seems to cause problems with core
. I am not completely sure what the best cause of action would be.
The problem here is that because the inner_type is in user space which errors if the user doesn't have extern crate core
. One solution would be do implement the inner_type two times for core
and std
, and then feature gate the implementation.
impl #std::fmt::Debug for #inner_name{
...
}
where #std
could be ::std
or ::core
. Otherwise I could try to find a different solution that doesn't require the inner type at all.
from enumflags.
Actually the bitflags create also creates everything in user space(macros) and it doesn't require the std
. https://doc.rust-lang.org/bitflags/src/bitflags/lib.rs.html#250-286
I'll look into it. Sorry for the back and forth, I haven't really done anything without the std
.
from enumflags.
The trick here is
#[allow(private_in_public)]
#[doc(hidden)]
pub use core as __core;
And then use ::__core
instead of ::core
. This solves your 1.
from enumflags.
I think we can't do that because it uses no_std
itself. It cannot be used in enumflags_derive
because we are using some std features for code generation, even if they don't show up in the final code.
Look at my last commit, I resolved the issue with a feature. The only problem left is from_bitflag
, which honestly I have no idea of what to do. I've never used quote!
nor procedural macros though.
from enumflags.
I don't meant that we should use it inside enumflags_derive
but in enumflags
. Then you can access it like this (because it is just a public re-export).
let i = enumflags::__core::option::Option::Some(42);
Which means that we can do something like this inside enumflags_derive
.
impl enumflags::__core::ops::BitOr for #inner_name{
type Output = Self;
fn bitor(self, other: Self) -> Self{
#inner_name(self.0 | other.0)
}
}
I got it working with the first version of your fork. Or at least it appears to be working. Do you want me to push the changes?
from enumflags.
Go ahead 👍 !
from enumflags.
I replaced bitflags with it and it works perfect!
from enumflags.
Sorry, I think it's better to keep it open until it's merged.
from enumflags.
Any progress here?
I just don't want println!
appeared in from_bits.
Thx
from enumflags.
Should be fixed in the latest released
from enumflags.
Related Issues (12)
- Feature request: Add a macro to specify multiple flags without repeating the type name HOT 3
- support type aliases HOT 1
- The from_bitflag method generates warnings about unused methods HOT 2
- proc-macro derive panicked with #[repr(u64)]: assertion failed: index < std::u32::MAX as usize
- Warning on nightly about implicit imports
- Version in repository does not match version on crates.io?
- Support Zero (0) value for discriminant HOT 2
- Support for const variants HOT 4
- Make missing flags detection optional HOT 1
- Multiple Bits for Flag HOT 4
- Specifying bits using bitshifting 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 enumflags.