Created
September 23, 2016 23:43
-
-
Save jimmycuadra/45d222b874af85ea4592e8077f0c4b76 to your computer and use it in GitHub Desktop.
Constructor in macro expansion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As is: | |
error: expected expression, found `AnswerEvent` | |
--> src/api/r0/event_creation.rs:42:9 | |
| | |
42 | $name { | |
| ^^^^^ | |
---------- | |
Changing $name from `ty` to `expr`: | |
error: macro expansion ignores token `{` and any following | |
--> src/api/r0/event_creation.rs:42:15 | |
| | |
42 | $name { | |
| ^ | |
| | |
note: caused by the macro expansion here; the usage of `construct_message_event!` is likely invalid in expression context | |
--> src/api/r0/event_creation.rs:127:17 | |
| | |
127| construct_message_event!(AnswerEvent) | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! construct_message_event { | |
($name:ty) => { | |
$name { | |
content: extract_event_content(event_content, &event_type)?, | |
event_id: event_id.clone(), | |
extra_content: (), | |
event_type: event_type.clone(), | |
room_id: room_id.clone(), | |
unsigned: None, | |
user_id: user.id.clone(), | |
}.try_into().map_err(ApiError::from)? | |
} | |
} | |
let room_event: NewEvent = match event_type { | |
EventType::CallAnswer => { | |
construct_message_event!(AnswerEvent) | |
} | |
_ => // ... | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment