-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing keformat! #437
Conversation
This PR introduces a very weird bug with rust-analyzer: rust-lang/rust-analyzer#14190 I propose we refrain on merging it to avoid users having a subpar experience with the macros and dismissing the feature until that issue is fixed. Can someone on the team with a Mac let me know if they're also affected (proc_macro build fails in RA only, I've confirmed it on Linux and Windows). |
I've just cloned the repo and on my Mac (Intel i5 - Ventura 13.1) I don't see any problem.
|
Approving this pull request. |
To help users with processing Key Expressions, here come KeFormats.
examples/examples/z_formats
shows how zenoh-rs users are expected to use thekeformat
macro:keformat!($spec: lit, $module: ident)
will declaremod $module
which contain all of the formatting utilities wrapped in helpers that provide accessors based on the$spec
:Format
is a ZST representing this exact format.formatter() -> Formatter
constructs a formatter with setters for each field of the spec.parser<'s>(&'s keyexpr) -> ZResult<Parsed<'s>>
parses the keyexpr into an annotated parsing result, with getters for each field of the spec.keformat!($formatter: expr, $($field: ident [ = $value: expr])*)
works on formatters constructed by the previously mentionedformatter()
function. It sets each$field
in the formatter, returning aZResult<&mut Formatter>
that will error if$value
doesn't fit$field
's spec. If no$value
is provided, the macro will assume a$field
variable exists and use it as$value
. The macro will detect attempt to set fields that don't exist.KeFormat
s can also be constructed at runtime, and the formatters and parse-results may be used respectively like read-only and write-only maps. APIs for other languages may be built on to of these.TODOs: