Who am I?
-
I’m the main developer of the swc project
-
Ask me about anything
-
How to reach me
Moved to https://github.com/dudykr/ddbase
Home Page: https://github.com/dudykr/ddbase
License: MIT License
I’m the main developer of the swc project
Ask me about anything
How to reach me
The macro currently generates as_variant()
, returning Option<&T>
. Could it also generate as_mut_variant()
, returning Option<&mut T>
?
Minimal reproducible example:
use is_macro::Is;
#[derive(Debug, Is)]
enum Foo {
A(u8),
B(u8, u8)
}
fn main() {
println!("Hello, world!");
}
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
--> src\main.rs:3:17
|
3 | #[derive(Debug, Is)]
| ^^ expected 2 fields, found 1
...
6 | B(u8, u8),
| --------- tuple variant defined here
error: aborting due to previous error
While we're adopting is-macro
in tbot
, we found that translation to snake_case
may yield a bit unexpected results around digits. For this enum, I would expect that the generated is_
method would be named is_video_mp4
, not is_video_mp_4
(notice the underscore before the number):
#[derive(Is)]
pub enum MimeType {
…
/// The `video/mp4` MIME type.
VideoMp4,
}
Such cases should probably be left to humans, because one might actually expect an underscore inserted between a word and a digit. I suggest an attribute, setting which changes the generated method names:
#[derive(Is)]
pub enum MimeType {
…
#[is(root = "video_mp4")]
VideoMp4,
}
With this attribute, Is
would generate is_video_mp4
instead of is_video_mp_4
. If it were possible for this variant, it would also emit expect_video_mp4
and video_mp4
instead of expect_video_mp_4
and video_mp_4
. This can be extended in the future with ability to choose names for each method or change their prefixes. The only downside to this is a more complicated implementation. Also, if this is going to be implemented, we should probably come up with a better name than root
.
(by the way, we really appreciate this crate for generating expect_
and taking methods, and also that we don't have to manually implement is_
methods
Minimal reproducible example:
use is_macro::Is;
#[derive(Is)]
enum Foo {
A(&'static u8),
}
error: proc-macro derive panicked
--> src\main.rs:3:10
|
3 | #[derive(Is)]
| ^^
|
= help: message: Quote::parse() failed.
Note: quasi quotting was invoked from:
D:\Tools\Rust\cargo\registry\src\github.com-1ecc6299db9ec823\is-macro-0.1.1\src\lib.rs:131:45
Error from syn: expected identifier
>>>>>
& 'static u8
<<<<<
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.