1use super::*;
18use crate::common::{SeparatedSeqAccept, Str};
19use crate::context::ContextProvides;
20use crate::{Output, SequenceAccept, Writable, WritableSeq};
21
22impl<O, Type> Writable<O> for UseType<Type>
23where
24 O: Output,
25 Type: Writable<O>,
26{
27 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
28 output.write("use ").await?;
29 self.0.write_to(output).await?;
30 output.write(";\n").await
31 }
32}
33
34impl<O, Cond, Attr> Writable<O> for CfgAttr<Cond, Attr>
35where
36 O: Output,
37 Cond: Writable<O>,
38 Attr: Writable<O>,
39{
40 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
41 output.write("cfg_attr(").await?;
42 self.0.write_to(output).await?;
43 output.write(", ").await?;
44 self.1.write_to(output).await?;
45 output.write(")").await
46 }
47}
48
49impl<O, Cond> Writable<O> for Cfg<Cond>
50where
51 O: Output,
52 Cond: Writable<O>,
53{
54 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
55 output.write("cfg(").await?;
56 self.0.write_to(output).await?;
57 output.write(")").await
58 }
59}
60
61impl<O, Value> Writable<O> for Target<Value>
62where
63 O: Output,
64 Value: Writable<O>,
65{
66 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
67 let (kind, value) = match self {
68 Self::Os(value) => ("os", value),
69 Self::Family(value) => ("family", value),
70 Self::Arch(value) => ("arch", value),
71 };
72 output.write("target_").await?;
73 output.write(kind).await?;
74 output.write(" = \"").await?;
75 value.write_to(output).await?;
76 output.write("\"").await
77 }
78}
79
80impl<O, Arg> Writable<O> for Link<Arg>
81where
82 O: Output,
83 Arg: Writable<O>,
84{
85 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
86 output.write("link(").await?;
87 self.0.write_to(output).await?;
88 output.write(")").await
89 }
90}
91
92impl<O> Writable<O> for NoMangle
93where
94 O: Output,
95 O::Ctx: ContextProvides<Edition>,
96{
97 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
98 let edition = output.get_ctx();
99 output
100 .write(if edition >= &Edition::Rust2024 {
101 "unsafe(no_mangle)"
102 } else {
103 "no_mangle"
104 })
105 .await
106 }
107}
108
109impl<O, Lints> Writable<O> for AllowLints<Lints>
110where
111 O: Output,
112 Lints: WritableSeq<O>,
113{
114 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
115 let mut acceptor = SeparatedSeqAccept::new(output, Str("allow("), Str(","));
116 self.0.for_each(&mut acceptor).await?;
117 if acceptor.wrote_any {
118 output.write(")").await?;
119 }
120 Ok(())
121 }
122}
123
124impl<O, Msg, Since> Writable<O> for Deprecated<Msg, Since>
125where
126 O: Output,
127 Msg: Writable<O>,
128 Since: Writable<O>,
129{
130 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
131 match self {
132 Self::Basic => output.write("deprecated").await,
133 Self::Message(msg) => {
134 output.write("deprecated = \"").await?;
135 msg.write_to(output).await?;
136 output.write("\"").await
137 }
138 Self::Full { since, note } => {
139 output.write("deprecated(since = \"").await?;
140 since.write_to(output).await?;
141 output.write("\", note = \"").await?;
142 note.write_to(output).await?;
143 output.write("\")").await
144 }
145 }
146 }
147}
148
149impl<O> Writable<O> for MustUse
150where
151 O: Output,
152{
153 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
154 output.write("must_use").await
155 }
156}
157
158impl<O> Writable<O> for ModPub
159where
160 O: Output,
161{
162 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
163 output.write("pub").await
164 }
165}
166
167impl<O, Abi> Writable<O> for ModUnsafeExtern<Abi>
168where
169 O: Output,
170 Abi: Writable<O>,
171{
172 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
173 output.write("unsafe extern \"").await?;
174 self.0.write_to(output).await?;
175 output.write("\"").await
176 }
177}
178
179impl<O, Abi, Body> Writable<O> for ExternBlock<Abi, Body>
180where
181 O: Output,
182 O::Ctx: ContextProvides<Edition>,
183 Abi: Writable<O>,
184 Body: Writable<O>,
185{
186 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
187 let edition = output.get_ctx();
188 if edition >= &Edition::Rust2024 {
189 output.write("unsafe ").await?;
190 }
191 output.write("extern \"").await?;
192 self.abi.write_to(output).await?;
193 output.write("\" {").await?;
194 self.body.write_to(output).await?;
195 output.write("}").await
196 }
197}
198
199impl<O, Name, Body> Writable<O> for ModBlock<Name, Body>
200where
201 O: Output,
202 Name: Writable<O>,
203 Body: Writable<O>,
204{
205 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
206 output.write("mod ").await?;
207 self.name.write_to(output).await?;
208 output.write(" {").await?;
209 self.body.write_to(output).await?;
210 output.write("}\n").await
211 }
212}
213
214impl<O, Cond, Body> Writable<O> for IfBlock<Cond, Body>
215where
216 O: Output,
217 Cond: Writable<O>,
218 Body: Writable<O>,
219{
220 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
221 output.write("if ").await?;
222 self.0.write_to(output).await?;
223 output.write(" {\n").await?;
224 self.1.write_to(output).await?;
225 output.write("\n}").await
226 }
227}
228
229impl<O, Before, After> Writable<O> for Else<Before, After>
230where
231 O: Output,
232 Before: Writable<O>,
233 After: Writable<O>,
234{
235 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
236 self.0.write_to(output).await?;
237 output.write(" else ").await?;
238 self.1.write_to(output).await
239 }
240}
241
242impl<O, Body> Writable<O> for Block<Body>
243where
244 O: Output,
245 Body: Writable<O>,
246{
247 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
248 output.write("{\n").await?;
249 self.0.write_to(output).await?;
250 output.write("\n}").await
251 }
252}
253
254impl<O: Output, Expr> Writable<O> for UnsafeBlock<Expr>
255where
256 Expr: Writable<O>,
257{
258 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
259 o.write("unsafe {\n").await?;
260 self.0.write_to(o).await?;
261 o.write("\n}").await?;
262 Ok(())
263 }
264}
265
266impl<O, InputVars, Expr> Writable<O> for Closure<InputVars, Expr>
267where
268 O: Output,
269 InputVars: WritableSeq<O>,
270 Expr: Writable<O>,
271{
272 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
273 o.write("|").await?;
274 self.input_vars
275 .for_each(&mut SeparatedSeqAccept::comma_separated(o))
276 .await?;
277 o.write("| {\n").await?;
278 self.inside_block.write_to(o).await?;
279 o.write("\n}").await?;
280 Ok(())
281 }
282}
283
284impl<O: Output, Recv, FuncName, Args> Writable<O> for FunctionCall<Recv, FuncName, Args>
285where
286 Recv: Writable<O>,
287 FuncName: Writable<O>,
288 Args: WritableSeq<O>,
289{
290 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
291 self.receiver.write_to(o).await?;
292 o.write(if self.is_assoc { "::" } else { "." }).await?;
293 self.name.write_to(o).await?;
294 AnonTuple(&self.args).write_to(o).await
295 }
296}
297
298impl<O: Output, Name, Args> Writable<O> for Turbofish<Name, Args>
299where
300 Name: Writable<O>,
301 Args: WritableSeq<O>,
302{
303 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
304 self.0.write_to(output).await?;
305 let mut acceptor = SeparatedSeqAccept::new(output, Str("::<"), Str(", "));
306 self.1.for_each(&mut acceptor).await?;
307 if acceptor.wrote_any {
308 output.write(">").await?;
309 }
310 Ok(())
311 }
312}
313
314impl<O, Expr> Writable<O> for Stmt<Expr>
315where
316 O: Output,
317 Expr: Writable<O>,
318{
319 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
320 self.0.write_to(output).await?;
321 output.write(";\n").await
322 }
323}
324
325impl<O: Output, Variable, Expr> Writable<O> for LetStmt<Variable, Expr>
326where
327 Variable: Writable<O>,
328 Expr: Writable<O>,
329{
330 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
331 Stmt(LetExpr(&self.0, &self.1)).write_to(o).await
332 }
333}
334
335impl<O: Output, Variable, Expr> Writable<O> for AssignStmt<Variable, Expr>
336where
337 Variable: Writable<O>,
338 Expr: Writable<O>,
339{
340 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
341 Stmt(AssignExpr(&self.0, &self.1)).write_to(o).await
342 }
343}
344
345impl<O, Expr> Writable<O> for ReturnStmt<Expr> where O: Output, Expr: Writable<O> {
346 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
347 o.write("return ").await?;
348 self.0.write_to(o).await?;
349 o.write(";\n").await
350 }
351}
352
353impl<O, Pattern, Expr> Writable<O> for LetExpr<Pattern, Expr>
354where
355 O: Output,
356 Pattern: Writable<O>,
357 Expr: Writable<O>,
358{
359 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
360 output.write("let ").await?;
361 AssignExpr(&self.0, &self.1).write_to(output).await
362 }
363}
364
365struct AssignExpr<Variable, Expr>(Variable, Expr);
366
367impl<O, Variable, Expr> Writable<O> for AssignExpr<Variable, Expr>
368where
369 O: Output,
370 Variable: Writable<O>,
371 Expr: Writable<O>,
372{
373 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
374 self.0.write_to(o).await?;
375 o.write(" = ").await?;
376 self.1.write_to(o).await
377 }
378}
379
380impl<O: Output, Elements> Writable<O> for ArrayFromElements<Elements>
381where
382 Elements: WritableSeq<O>,
383{
384 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
385 o.write("[").await?;
386 self.0
387 .for_each(&mut SeparatedSeqAccept::comma_separated(o))
388 .await?;
389 o.write("]").await
390 }
391}
392
393impl<O: Output, Cont, Item> Writable<O> for AssociatedItem<Cont, Item>
394where
395 Cont: Writable<O>,
396 Item: Writable<O>,
397{
398 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
399 self.0.write_to(o).await?;
400 o.write("::").await?;
401 self.1.write_to(o).await
402 }
403}
404
405impl<O: Output, Expr> Writable<O> for QuestionMarkAfter<Expr>
406where
407 Expr: Writable<O>,
408{
409 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
410 self.0.write_to(o).await?;
411 o.write("?").await?;
412 Ok(())
413 }
414}
415
416impl<O: Output, Expr> Writable<O> for OkResultOf<Expr>
417where
418 Expr: Writable<O>,
419{
420 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
421 o.write("Ok(").await?;
422 self.0.write_to(o).await?;
423 o.write(")").await?;
424 Ok(())
425 }
426}
427
428impl<O: Output, Type, Trait> Writable<O> for TypeAsTrait<Type, Trait>
429where
430 Type: Writable<O>,
431 Trait: Writable<O>,
432{
433 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
434 o.write("<").await?;
435 self.0.write_to(o).await?;
436 o.write(" as ").await?;
437 self.1.write_to(o).await?;
438 o.write(">").await?;
439 Ok(())
440 }
441}
442
443impl<O, Mods, Name, Args, Return, Where, Body> Writable<O>
444 for FunctionDef<Mods, Name, Args, Return, Where, Body>
445where
446 O: Output,
447 Mods: WritableSeq<O>,
448 Name: Writable<O>,
449 Args: WritableSeq<O>,
450 Return: Writable<O>,
451 Where: WritableSeq<O>,
452 Body: Writable<O>,
453{
454 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
455 self.mods.for_each(&mut ModsAccept(o)).await?;
456 o.write("fn ").await?;
457 self.name.write_to(o).await?;
458 AnonTuple(&self.args).write_to(o).await?;
459 o.write(" -> ").await?;
460 self.return_type.write_to(o).await?;
461 self.where_conds.for_each(&mut where_cond_accept(o)).await?;
462 self.body.write_to(o).await?;
463 o.write("\n").await?;
464 Ok(())
465 }
466}
467
468impl<O: Output> Writable<O> for FunctionBodyDeclare {
469 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
470 output.write(";").await
471 }
472}
473
474impl<O: Output, Inner> Writable<O> for FunctionBodyImplement<Inner>
475where
476 Inner: Writable<O>,
477{
478 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
479 Block(&self.0).write_to(output).await
480 }
481}
482
483impl<O, Args, Return> Writable<O> for FunctionPtr<Args, Return>
484where
485 O: Output,
486 Args: WritableSeq<O>,
487 Return: Writable<O>,
488{
489 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
490 let kind = match self.kind {
491 FunctionPtrKind::FnPtr => "fn",
492 FunctionPtrKind::Fn => "Fn",
493 FunctionPtrKind::FnMut => "FnMut",
494 FunctionPtrKind::FnOnce => "FnOnce",
495 };
496 output.write(kind).await?;
497 AnonTuple(&self.args).write_to(output).await?;
498 output.write(" -> ").await?;
499 self.return_type.write_to(output).await
500 }
501}
502
503impl<O: Output, Type, Value> Writable<O> for AssociatedTypeEquals<Type, Value>
504where
505 Type: Writable<O>,
506 Value: Writable<O>,
507{
508 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
509 self.0.write_to(o).await?;
510 o.write("=").await?;
511 self.1.write_to(o).await
512 }
513}
514
515impl<O: Output, Type> Writable<O> for DynOf<Type>
516where
517 Type: Writable<O>,
518{
519 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
520 o.write("dyn ").await?;
521 self.0.write_to(o).await
522 }
523}
524
525impl<O: Output, Type> Writable<O> for RefOf<Type>
526where
527 Type: Writable<O>,
528{
529 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
530 o.write("&").await?;
531 self.0.write_to(o).await
532 }
533}
534
535impl<O: Output, Type> Writable<O> for ImplOf<Type>
536where
537 Type: Writable<O>,
538{
539 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
540 o.write("impl ").await?;
541 self.0.write_to(o).await
542 }
543}
544
545impl<O: Output, Type> Writable<O> for LifetimedRefOf<'_, Type>
546where
547 Type: Writable<O>,
548{
549 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
550 o.write("&'").await?;
551 o.write(self.0).await?;
552 o.write(" ").await?;
553 self.1.write_to(o).await
554 }
555}
556
557impl<O: Output, VarName, Value> Writable<O> for AssociatedTypeDef<VarName, Value>
558where
559 VarName: Writable<O>,
560 Value: Writable<O>,
561{
562 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
563 o.write("\ntype ").await?;
564 self.0.write_to(o).await?;
565 o.write(" = ").await?;
566 self.1.write_to(o).await?;
567 o.write(";\n").await?;
568 Ok(())
569 }
570}
571
572impl<O, Mods, Name, TypeVars, SuperTraits, Body> Writable<O>
573 for TraitDef<Mods, Name, TypeVars, SuperTraits, Body>
574where
575 O: Output,
576 Mods: WritableSeq<O>,
577 Name: Writable<O>,
578 TypeVars: WritableSeq<O>,
579 SuperTraits: WritableSeq<O>,
580 Body: Writable<O>,
581{
582 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
583 self.mods.for_each(&mut ModsAccept(o)).await?;
584 o.write("trait ").await?;
585 self.name.write_to(o).await?;
586 TypeArgAccept::new(o)
587 .write_inside_diamond(&self.type_variables)
588 .await?;
589 self.super_traits
590 .for_each(&mut type_arg_bound_accept(o))
591 .await?;
592 o.write(" {").await?;
593 self.body.write_to(o).await?;
594 o.write("}").await?;
595 Ok(())
596 }
597}
598
599impl<O, TypeVars, Trait, Recv, Where, Body> Writable<O>
600 for TraitImpl<TypeVars, Trait, Recv, Where, Body>
601where
602 O: Output,
603 TypeVars: WritableSeq<O>,
604 Trait: Writable<O>,
605 Recv: Writable<O>,
606 Where: WritableSeq<O>,
607 Body: Writable<O>,
608{
609 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
610 o.write("impl").await?;
611 TypeArgAccept::new(o)
612 .write_inside_diamond(&self.type_variables)
613 .await?;
614 o.write(" ").await?;
615 self.the_trait.write_to(o).await?;
616 o.write(" for ").await?;
617 self.receiver.write_to(o).await?;
618 self.where_conds.for_each(&mut where_cond_accept(o)).await?;
619 o.write(" {").await?;
620 self.body.write_to(o).await?;
621 o.write("}").await?;
622 Ok(())
623 }
624}
625
626impl<O, Mods, Name, Elements> Writable<O> for StructDef<Mods, Name, Elements>
627where
628 O: Output,
629 Mods: WritableSeq<O>,
630 Name: Writable<O>,
631 Elements: WritableSeq<O>,
632{
633 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
634 self.mods.for_each(&mut ModsAccept(o)).await?;
635 o.write("struct ").await?;
636 match &self.kind {
637 StructKind::Tuple(name, elements) => {
638 NamedTuple {
639 name,
640 args: elements,
641 }
642 .write_to(o)
643 .await?;
644 o.write(";").await
645 }
646 StructKind::NamedFields(name, elements) => {
647 StructCall {
648 name,
649 body: StructFields(elements),
650 }
651 .write_to(o)
652 .await
653 }
654 }
655 }
656}
657
658impl<O, Name, Body> Writable<O> for StructCall<Name, Body>
659where
660 O: Output,
661 Name: Writable<O>,
662 Body: Writable<O>,
663{
664 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
665 self.name.write_to(o).await?;
666 o.write(" { ").await?;
667 self.body.write_to(o).await?;
668 o.write(" }").await
669 }
670}
671
672impl<O, Fields> Writable<O> for StructFields<Fields>
673where
674 O: Output,
675 Fields: WritableSeq<O>,
676{
677 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
678 self.0.for_each(&mut struct_fields_accept(output)).await
679 }
680}
681
682impl<O, Name, Value> Writable<O> for DeclareField<Name, Value>
683where
684 O: Output,
685 Name: Writable<O>,
686 Value: Writable<O>,
687{
688 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
689 FunctionParam(&self.0, &self.1).write_to(o).await
690 }
691}
692
693impl<O, Name, Args> Writable<O> for NamedTuple<Name, Args>
694where
695 O: Output,
696 Name: Writable<O>,
697 Args: WritableSeq<O>,
698{
699 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
700 self.name.write_to(output).await?;
701 let mut separator = SeparatedSeqAccept::new(output, Str("("), Str(", "));
703 self.args.for_each(&mut separator).await?;
704 if separator.wrote_any {
705 output.write(")").await?;
706 }
707 Ok(())
708 }
709}
710
711impl<O, Args> Writable<O> for AnonTuple<Args>
712where
713 O: Output,
714 Args: WritableSeq<O>,
715{
716 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
717 o.write("(").await?;
718 self.0
719 .for_each(&mut SeparatedSeqAccept::comma_separated(o))
720 .await?;
721 o.write(")").await
722 }
723}
724
725impl<O, Attr, Value> Writable<O> for WithAttributes<Attr, Value>
726where
727 O: Output,
728 Attr: WritableSeq<O>,
729 Value: Writable<O>,
730{
731 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
732 self.attr
733 .for_each(&mut AttributesAccept::with_separator(
734 output,
735 self.separator,
736 ))
737 .await?;
738 self.value.write_to(output).await
739 }
740}
741
742impl<O, Mods, Name, Entries> Writable<O> for EnumDef<Mods, Name, Entries>
743where
744 O: Output,
745 Mods: WritableSeq<O>,
746 Name: Writable<O>,
747 Entries: WritableSeq<O>,
748{
749 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
750 self.mods.for_each(&mut ModsAccept(output)).await?;
751 output.write("enum ").await?;
752 self.name.write_to(output).await?;
753 output.write(" {").await?;
754 self.entries
755 .for_each(&mut SeparatedSeqAccept::comma_separated(output))
756 .await?;
757 output.write("}").await
758 }
759}
760
761impl<O, Name, TypeArgs> Writable<O> for Parameterized<Name, TypeArgs>
762where
763 O: Output,
764 Name: Writable<O>,
765 TypeArgs: WritableSeq<O>,
766{
767 async fn write_to(&self, o: &mut O) -> Result<(), O::Error> {
768 self.name.write_to(o).await?;
769 TypeArgAccept::new(o)
770 .write_inside_diamond(&self.type_args)
771 .await
772 }
773}
774
775impl<O, TypeVar, Bounds> Writable<O> for BoundedTypeVar<TypeVar, Bounds>
776where
777 O: Output,
778 TypeVar: Writable<O>,
779 Bounds: WritableSeq<O>,
780{
781 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
782 self.0.write_to(output).await?;
783 self.1.for_each(&mut type_arg_bound_accept(output)).await
784 }
785}
786
787impl<O> Writable<O> for Lifetime<'_>
788where
789 O: Output,
790{
791 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
792 output.write("'").await?;
793 output.write(self.0).await
794 }
795}
796
797impl<O, Name, Type> Writable<O> for FunctionParam<Name, Type>
798where
799 O: Output,
800 Name: Writable<O>,
801 Type: Writable<O>,
802{
803 async fn write_to(&self, output: &mut O) -> Result<(), O::Error> {
804 self.0.write_to(output).await?;
805 output.write(": ").await?;
806 self.1.write_to(output).await
807 }
808}
809
810struct ModsAccept<'o, O>(&'o mut O);
815
816impl<'o, O: Output> SequenceAccept<O> for ModsAccept<'o, O> {
817 async fn accept<W>(&mut self, writable: &W) -> Result<(), O::Error>
818 where
819 W: Writable<O>,
820 {
821 writable.write_to(&mut self.0).await?;
822 self.0.write(" ").await
823 }
824}
825
826struct TypeArgAccept<'o, O> {
827 inner: SeparatedSeqAccept<'o, O, Str<&'static str>, Str<&'static str>>,
828}
829
830impl<'o, O> TypeArgAccept<'o, O> {
831 fn new(output: &'o mut O) -> Self {
832 Self {
833 inner: SeparatedSeqAccept::new(output, Str("<"), Str(", ")),
834 }
835 }
836}
837
838impl<'o, O> TypeArgAccept<'o, O>
839where
840 O: Output,
841{
842 async fn write_inside_diamond<TypeArgs>(&mut self, type_args: &TypeArgs) -> Result<(), O::Error>
843 where
844 TypeArgs: WritableSeq<O>,
845 {
846 type_args.for_each(&mut self.inner).await?;
847 if self.inner.wrote_any {
848 self.inner.output.write(">").await?;
849 }
850 Ok(())
851 }
852}
853
854fn type_arg_bound_accept<'o, O>(
855 output: &'o mut O,
856) -> SeparatedSeqAccept<'o, O, Str<&'static str>, Str<&'static str>> {
857 SeparatedSeqAccept::new(output, Str(": "), Str(" + "))
858}
859
860fn struct_fields_accept<'o, O>(
861 output: &'o mut O,
862) -> SeparatedSeqAccept<'o, O, Str<&'static str>, Str<&'static str>> {
863 SeparatedSeqAccept::new(output, Str("\n"), Str(",\n"))
864}
865
866fn where_cond_accept<'o, O>(
867 output: &'o mut O,
868) -> SeparatedSeqAccept<'o, O, Str<&'static str>, Str<&'static str>> {
869 SeparatedSeqAccept::new(output, Str(" where "), Str(", "))
870}