Skip to content

Commit

Permalink
Move generated empty enum types to module
Browse files Browse the repository at this point in the history
They need to publicly accessible after all, for the Context and
Subsystem trait bounds.

Signed-off-by: Bernhard Schuster <bernhard@ahoi.io>
  • Loading branch information
drahnr committed Dec 9, 2022
1 parent 66b9319 commit 0b2982e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 16 additions & 2 deletions orchestra/proc-macro/src/impl_subsystem_ctx_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ pub(crate) fn impl_subsystem_types_all(info: &OrchestraInfo) -> Result<TokenStre
let outgoing_wrapper = &Ident::new(&(subsystem_name.clone() + "OutgoingMessages"), span);
let message_to_consume = ssf.message_to_consume();

ts.extend(ssf.maybe_dummy_message_tokenstream());

let subsystem_ctx_trait = &Ident::new(&(subsystem_name.clone() + "ContextTrait"), span);
let subsystem_sender_trait = &Ident::new(&(subsystem_name.clone() + "SenderTrait"), span);

Expand All @@ -137,6 +135,22 @@ pub(crate) fn impl_subsystem_types_all(info: &OrchestraInfo) -> Result<TokenStre
ts.extend(impl_wrapper_enum(&outgoing_wrapper, ssf.messages_to_send.as_slice())?);
}

// generate the empty dummy messages, where needed
ts.extend({
let mut messages = TokenStream::new();
for ssf in info.subsystems() {
messages.extend(ssf.gen_dummy_message_ty());
}
quote! {
#[doc = r###"Generated dummy messages, only!
Meant to be used in conjunection with your own defined messages"###]
pub mod messages {
#messages
}
}
});

// impl the emtpy tuple handling for tests
let empty_tuple: Type = parse_quote! { () };
ts.extend(impl_subsystem_context_trait_for(
Expand Down
11 changes: 9 additions & 2 deletions orchestra/proc-macro/src/parse/parse_orchestra_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub(crate) struct SubSysField {

impl SubSysField {
pub(crate) fn dummy_msg_name(&self) -> Ident {
Ident::new(format!("{}DummyMessage", self.generic).as_str(), self.name.span())
Ident::new(format!("{}Message", self.generic).as_str(), self.name.span())
}

/// Returns either the specified to be consumed messsage
Expand All @@ -122,10 +122,17 @@ impl SubSysField {
}
}

pub(crate) fn maybe_dummy_message_tokenstream(&self) -> TokenStream {
/// Generate the dummy message type if the subsystem does not consume one
///
/// Note: Only required to the internal structure anchoring everything to
/// the consuming message type. See #11 for a full solution.
pub(crate) fn gen_dummy_message_ty(&self) -> TokenStream {
if self.message_to_consume.is_none() {
let dummy_msg_ident = self.dummy_msg_name();
quote! {
#[doc =
r###"A dummy implementation to satisfy the current internal structure
and cannot be constructed delibarately, since it's not meant to be sent or used at all"###]
#[derive(Debug, Clone, Copy)]
pub enum #dummy_msg_ident {}
}
Expand Down

0 comments on commit 0b2982e

Please sign in to comment.