Comments (5)
@magiclen, could I get your thoughts on this? I'm not great at macros, but I could take a crack at this if it is likely to get merged if I get it working.
from educe.
I'm not sure what you mean but for now I think you can just use
#[derive(Clone, Debug, Educe)]
#[educe(Default)]
pub struct Ipv4Range {
#[educe(Default(expression = "[0, 0, 0, 0].into()"))]
pub first: std::net::Ipv4Addr,
#[educe(Default(expression = "[255, 255, 255, 255].into()"))]
pub last: std::net::Ipv4Addr,
}
from educe.
I am aware I can do that, but I was hoping to avoid having to modify the code generation of the members to add this to every member. It is easier if I can tell educe at the struct level macro invocation that "when it sees any "Ipv4Addr" member, here is the value it should use as the default".
from educe.
Okay, I see.
I have a question. How can you tell Ipv4Addr
are the same struct or not? If the code is like this,
mod a {
pub struct Ipv4Addr(u32);
}
struct Ipv4Addr;
#[derive(Clone, Debug)]
#[educe(Default(literals = (Ipv4Addr = [0,0,0,0], Ipv6Addr = [0,0,0,0,...])))]
pub struct Ipv4Range {
#[educe(Default)]
pub first: std::net::Ipv4Addr,
pub last: Ipv4Addr,
}
from educe.
I am doing codegen of the structs, so I know what types the members can be, and cant be. c.f. oxidecomputer/typify#184
from educe.
Related Issues (17)
- Multiple bounds are confused HOT 2
- PartialEq macro generates incorrect code HOT 1
- `#[derive(Serde)]` shorthand for `#[derive(Serialize, Deserialize)]` HOT 1
- `educe` uses legacy (^1) version of `syn` crate. HOT 3
- Panic when other attributes contain non-literal tokens
- Missing white spaces in default expressions HOT 1
- Debug for unions is unsound, exposes uninitialized memory HOT 4
- Name collision if an enum field is named `f` or `builder` HOT 3
- Suggestions for reducing implementation code duplication
- Wrong bounds applied to derived impls HOT 3
- Namespace problems with MyDebug, RawString, and possibly others
- Explicitly defining bounds with multiple traits leads to spurious bounds HOT 3
- Version 0.5.12 contains breaking changes. HOT 5
- Handle recursive enum HOT 1
- bug(Debug): error[E0275]: overflow evaluating the requirement `engine::tests::borsh_diff::Sequence2TupleEntryChange<'_, &engine::tests::borsh_diff::BorshView, &engine::tests::borsh_diff::BorshView>: std::marker::Sized` HOT 1
- Help with Default with generics not working.
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 educe.