Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions progenitor-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,22 @@ impl Generator {

let types = self.type_space.to_stream();

// Re-export replaced types from the types module so callers can access
// them without knowing the replacement path.
let mut sorted_replace: Vec<_> = self.settings.replace.iter().collect();
sorted_replace.sort_by_key(|(name, _)| name.as_str());
let replaced_type_reexports =
sorted_replace.iter().map(|(type_name, (replace_path, _))| {
let type_ident = quote::format_ident!("{}", type_name);
let replace_tokens: TokenStream =
replace_path.parse().expect("invalid replacement type path");
quote! {
#[allow(unused_imports)]
pub use #replace_tokens as #type_ident;
}
});
let replaced_type_reexports = quote! { #(#replaced_type_reexports)* };
Comment on lines +379 to +391
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed, I think this may make more sense in typify.

Do we think this should be the only behavior or should be opt-in (or opt-out)?

What if there's a replace imperative that's never used? Is that caught elsewhere? Would we want to check for that?

Would we want to do something for the other ways to replace a type such as x-rust-type.


let (inner_type, inner_fn_value) = match self.settings.inner_type.as_ref() {
Some(inner_type) => (inner_type.clone(), quote! { &self.inner }),
None => (quote! { () }, quote! { &() }),
Expand Down Expand Up @@ -440,6 +456,7 @@ impl Generator {
#[allow(clippy::all)]
pub mod types {
#types
#replaced_type_reexports
}

#[derive(Clone, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions progenitor/tests/build_nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ mod builder_untagged {
pub fn _ignore() {
// Verify the replacement above.
let _ignore = nexus_client::types::IpNet::V4("".parse().unwrap());
// Verify the replaced type is re-exported from types.
let _: nexus_client::types::Ipv4Net = "".parse().unwrap();

let client = Client::new("");
let stream = client
Expand Down
Loading