2 releases
0.0.2 | Nov 26, 2021 |
---|---|
0.0.1 | Nov 26, 2021 |
#2265 in Procedural macros
108 downloads per month
22KB
393 lines
utility types
WIP
This crate use proc-macro to realize several utility types of TypeScript
Example
source code:
#[partial(PartialArticle)]
#[pick(ContentComments, [content, comments], [Debug])]
#[omit(AuthorLikedComments, [content], [])]
pub struct Article<T> {
author: String,
content: String,
liked: usize,
comments: T,
}
generated code:
pub struct Article<T> {
author: String,
content: String,
liked: usize,
comments: T,
}
pub struct AuthorLikedComments<T> {
author: String,
liked: usize,
comments: T,
}
#[derive(Debug)]
pub struct ContentComments<T> {
content: String,
comments: T,
}
Known Issue
Currently I don't analyze which generic is used in the generated struct or enum. So rustc will complain if the field with generic is not included in the generated struct or enum.
lib.rs
:
utility_types
This crate use proc-macro to realize several utility types of TypeScript
macro | TypeScript Utility Type |
---|---|
[macro@partial] | Partial<Type> |
[macro@required] | Required<Type> |
[macro@pick] | Pick<Type, Keys> |
[macro@omit] | Omit<Type, Keys> |
[macro@exclude] | Exclude<Type, ExcludedUnion> |
[macro@extract] | Extract<Type, Union> |
Dependencies
~1.5MB
~35K SLoC