(&mut self)
| 506 | } |
| 507 | |
| 508 | fn finish_runtime_module(&mut self) { |
| 509 | if !self.rt_module.is_empty() { |
| 510 | // As above, disable rustfmt, as we use prettyplease. |
| 511 | if self.opts.format { |
| 512 | uwriteln!(self.src, "#[rustfmt::skip]"); |
| 513 | } |
| 514 | |
| 515 | self.src.push_str("mod _rt {\n"); |
| 516 | self.src |
| 517 | .push_str("#![allow(dead_code, unused_imports, clippy::all)]\n"); |
| 518 | let mut emitted = IndexSet::new(); |
| 519 | while !self.rt_module.is_empty() { |
| 520 | for item in mem::take(&mut self.rt_module) { |
| 521 | if emitted.insert(item) { |
| 522 | self.emit_runtime_item(item); |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | self.src.push_str("}\n"); |
| 527 | } |
| 528 | |
| 529 | if !self.future_payloads.is_empty() { |
| 530 | let async_support = self.async_support_path(); |
| 531 | self.src.push_str(&format!( |
| 532 | "\ |
| 533 | pub mod wit_future {{ |
| 534 | #![allow(dead_code, unused_variables, clippy::all)] |
| 535 | |
| 536 | #[doc(hidden)] |
| 537 | pub trait FuturePayload: Unpin + Sized + 'static {{ |
| 538 | const VTABLE: &'static {async_support}::FutureVtable<Self>; |
| 539 | }}" |
| 540 | )); |
| 541 | for code in self.future_payloads.values() { |
| 542 | self.src.push_str(code); |
| 543 | } |
| 544 | self.src.push_str(&format!( |
| 545 | "\ |
| 546 | /// Creates a new Component Model `future` with the specified payload type. |
| 547 | /// |
| 548 | /// The `default` function provided computes the default value to be sent in |
| 549 | /// this future if no other value was otherwise sent. |
| 550 | pub fn new<T: FuturePayload>(default: fn() -> T) -> ({async_support}::FutureWriter<T>, {async_support}::FutureReader<T>) {{ |
| 551 | unsafe {{ {async_support}::future_new::<T>(default, T::VTABLE) }} |
| 552 | }} |
| 553 | }} |
| 554 | ", |
| 555 | )); |
| 556 | } |
| 557 | |
| 558 | if !self.stream_payloads.is_empty() { |
| 559 | let async_support = self.async_support_path(); |
| 560 | self.src.push_str(&format!( |
| 561 | "\ |
| 562 | pub mod wit_stream {{ |
| 563 | #![allow(dead_code, unused_variables, clippy::all)] |
| 564 | |
| 565 | pub trait StreamPayload: Unpin + Sized + 'static {{ |
no test coverage detected