async_codegen/rust/
mod.rs

1/*
2 * Copyright © 2025 Anand Beh
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//!
18//! Rust syntax elements.
19//!
20//! Note that no checking exists to make sure the elements are used correctly, i.e. the correct
21//! combination of structs. Instead, the library user is expected to have basic knowledge of how
22//! Rust syntax is composed, and to combine the structs in this module likewise.
23//!
24//! Example:
25//!
26//! ```
27//! # use async_codegen::common::{CombinedSeq, NoOpSeq, SingularSeq, Str};
28//! # use async_codegen::{Output, Writable};
29//! # use async_codegen::rust::{CanHaveAttributes, CfgAttr, Deprecated, FunctionBodyImplement, FunctionDef, FunctionParam, ModPub, MustUse, NoMangle, Parameterized};
30//!
31//! async fn write_function<O>(output: &mut O) -> Result<(), O::Error> where O: Output {
32//!   // For more advanced usage, you can replace Str("") by other Writable implementations
33//!   let function_def = FunctionDef {
34//!     mods: SingularSeq(ModPub),
35//!     name: Str("my_func"),
36//!     args: CombinedSeq(
37//!      SingularSeq(FunctionParam(Str("var1"), Str("Type"))),
38//!      SingularSeq(FunctionParam(Str("var2"), Parameterized::new(Str("Option"), SingularSeq(Str("bool")))))
39//!     ),
40//!     return_type: Parameterized::new(Str("Box"), SingularSeq(Str("str"))),
41//!     where_conds: NoOpSeq,
42//!     body: FunctionBodyImplement(Str("todo!()"))
43//!   };
44//!   function_def.write_to(output).await
45//!   // Will render as:
46//!   /*
47//!   pub fn my_func(var1: Type, var2: Option<bool>) -> Box<str> {
48//!     todo!()
49//!   }
50//!    */
51//! }
52//! ```
53//!
54
55use crate::common::{Combined, NoOp, NoOpSeq, Str, SurroundingSeqAccept};
56use crate::{Output, SequenceAccept, Writable};
57use std::fmt::Debug;
58
59mod syntax;
60#[cfg(test)]
61mod tests;
62
63/// All possible Rust editions.
64/// This is the only type in this module meant to be used as context, and not as a writable itself.
65#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
66#[non_exhaustive]
67pub enum Edition {
68    /// This Rust edition is declared for usability purposes. However, not all [crate::Writable]
69    /// implementations are guaranteed to work with it.
70    Rust2015,
71    Rust2018,
72    Rust2021,
73    Rust2024,
74}
75
76/// Imports a single type so that it can be used later.
77/// Renders as `use Type;`. Adds a new line after the semicolon.
78#[derive(Clone, Debug)]
79pub struct UseType<Type>(pub Type);
80
81/// An attribute enabled conditionally, i.e. `#[cfg_attr(Cond, Attr)]`
82#[derive(Clone, Debug)]
83pub struct CfgAttr<Cond, Attr>(pub Cond, pub Attr);
84
85/// A cfg attribute. Renders as `cfg(Cond)`.
86#[derive(Clone, Debug)]
87pub struct Cfg<Cond>(pub Cond);
88
89/// A cfg condition for targeting an OS, OS family, or architecture. For example:
90/// ```
91/// # use async_codegen::common::{NoOpSeq, SingularSeq, Str};
92/// # use async_codegen::context::EmptyContext;
93/// # use async_codegen::rust::{FunctionBodyDeclare, Cfg, FunctionDef, Target, CanHaveAttributes};
94/// # use async_codegen::util::InMemoryOutput;
95/// let function = FunctionDef {
96///   mods: NoOpSeq,
97///   name: Str("conditional_func"),
98///   args: NoOpSeq,
99///   return_type: Str("()"),
100///   where_conds: NoOpSeq,
101///   body: FunctionBodyDeclare
102/// }.with_attributes(
103///   SingularSeq(Cfg(Target::Os(Str("linux"))))
104/// );
105/// let string = InMemoryOutput::print_output(EmptyContext, &function);
106/// assert_eq!("#[cfg(target_os = \"linux\")]\nfn conditional_func() -> ();\n", string);
107/// ```
108#[derive(Clone, Debug)]
109pub enum Target<Value> {
110    Os(Value),
111    Family(Value),
112    Arch(Value),
113}
114
115/// The link attribute.
116#[derive(Clone, Debug)]
117pub struct Link<Arg>(pub Arg);
118
119/// The no mangle attribute.
120///
121/// Requires that the context satisfies [ContextProvides] for [Edition], because in Rust 2024 and
122/// beyond, the no-mangle attribute is an unsafe attribute.
123#[derive(Clone, Debug)]
124pub struct NoMangle;
125
126/// The attribute content for `allow(...)`. The tuple value must be a sequence.
127#[derive(Clone, Debug)]
128pub struct AllowLints<Lints>(pub Lints);
129
130/// The deprecated attribute. The three variants of this enum correspond to the deprecated
131/// attribute's multiple ways of being specified. See:
132/// https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
133#[derive(Clone, Debug)]
134pub enum Deprecated<Msg, Since = NoOp> {
135    Basic,
136    Message(Msg),
137    Full { since: Since, note: Msg },
138}
139
140impl Default for Deprecated<NoOp, NoOp> {
141    fn default() -> Self {
142        Self::Basic
143    }
144}
145
146impl Deprecated<NoOp, NoOp> {
147    pub fn basic() -> Self {
148        Self::Basic
149    }
150}
151
152impl<Msg> Deprecated<Msg> {
153    pub fn with_message(msg: Msg) -> Self {
154        Self::Message(msg)
155    }
156}
157
158/// The must_use attribute
159#[derive(Clone, Debug)]
160pub struct MustUse;
161
162/// The public modifier
163#[derive(Clone, Debug)]
164pub struct ModPub;
165
166/// The extern modifier, with the ABI selected as the tuple value.
167///
168/// This struct includes `unsafe`. Since Rust 2024, the unsafe keyword is required for extern
169/// functions, and before Rust 2024 it is optional. To make it easy to generate code targeting
170/// multiple editions, we unconditionally emit the "unsafe" keyword alongside "extern".
171#[derive(Clone, Debug)]
172pub struct ModUnsafeExtern<Abi>(pub Abi);
173
174/// A let statement. This statement includes the semicolon and a new line.
175#[derive(Clone, Debug)]
176pub struct LetStmt<Variable, Expr>(pub Variable, pub Expr);
177
178/// An assignation. This statement includes the semicolon and a new line.
179#[derive(Clone, Debug)]
180pub struct AssignStmt<Variable, Expr>(pub Variable, pub Expr);
181
182/// An array literal with predefined elements written out.
183/// Renders as `[E1, E2, E3, ...]` where EX is in the element sequence.
184#[derive(Clone, Debug)]
185pub struct ArrayFromElements<Elements>(pub Elements);
186
187/// An item attached to an associated container, via "::".
188/// The output will look like `Cont::Item`.
189#[derive(Clone, Debug)]
190pub struct AssociatedItem<Cont, Item>(pub Cont, pub Item);
191
192/// A question mark following another expression.
193#[derive(Clone, Debug)]
194pub struct QuestionMarkAfter<Expr>(pub Expr);
195
196/// Wraps an expression in `Ok(EXPR)`.
197#[derive(Clone, Debug)]
198pub struct OkResultOf<Expr>(pub Expr);
199
200/// Uses the `as` expression to perform a qualified trait cast (ready for a method call).
201/// I.e., this will render as `<Type as Trait>`.
202#[derive(Clone, Debug)]
203pub struct TypeAsTrait<Type, Trait>(pub Type, pub Trait);
204
205/// Declaration of an extern block, i.e. for FFI.
206/// In Rust 2024 and later, the unsafe keyword must be added for extern blocks. Thus, this struct
207/// requires that the context satisfies [ContextProvides] for [Edition].
208#[derive(Clone, Debug)]
209pub struct ExternBlock<Abi, Body> {
210    /// The ABI chosen. Must be writable
211    pub abi: Abi,
212    /// The body of the extern block. Must be writable
213    pub body: Body,
214}
215
216impl<Abi, Body> CanHaveAttributes for ExternBlock<Abi, Body> {
217    fn with_attributes<Attr>(self, attr: Attr) -> WithAttributes<Attr, Self> {
218        WithAttributes {
219            attr,
220            separator: "\n",
221            value: self,
222        }
223    }
224}
225
226/// Places the expression inside an unsafe block.
227/// Adds new lines inside the brackets, wrapping the inner expression.
228#[derive(Clone, Debug)]
229pub struct UnsafeBlock<Expr>(pub Expr);
230
231/// Writes a closure.
232/// Adds new lines inside the brackets, wrapping the inner expression.
233#[derive(Clone, Debug)]
234pub struct Closure<InputVars, Expr> {
235    /// The input variables.
236    /// Should be a sequence. They will be comma separated and placed within the pipes.
237    /// To use no input variables, use [NoOpSeq].
238    pub input_vars: InputVars,
239    /// The expression inside the closure block.
240    pub inside_block: Expr,
241}
242
243/// Performs a call to a function inside code.
244#[derive(Clone, Debug)]
245pub struct FunctionCall<Recv, Name, Args> {
246    /// The function receiver
247    pub receiver: Recv,
248    /// Whether the function is associated, false if it's a method
249    pub is_assoc: bool,
250    /// The function name
251    pub name: Name,
252    /// The arguments. Must be a sequence
253    pub args: Args,
254}
255
256/// Provides access to the "turbofish" syntax, i.e. `Name::<Args>`.
257/// The first tuple value must be writable, and the second must be a sequence.
258/// 
259/// Note that if the sequence outputs nothing, this struct will behave as if no args were
260/// specified. I.e. `Turbofish(Name, NoOpSeq)` is equivalent to just `Name`.
261#[derive(Clone, Debug)]
262pub struct Turbofish<Name, Args>(pub Name, pub Args);
263
264/// A function declaration
265#[derive(Clone, Debug)]
266pub struct FunctionDef<Mods, Name, Args, Return, Where, Body> {
267    /// The modifiers. Must be a sequence.
268    pub mods: Mods,
269    /// The function name. Type variables can be declared here via [Parameterized]
270    pub name: Name,
271    /// The arguments. Must be a sequence
272    pub args: Args,
273    /// The return type, i.e. after the `->` arrow
274    pub return_type: Return,
275    /// The "where" conditions. Must be a sequence. Set to [NoOp] to disable.
276    /// Will render as `where C1, C2, C3, ...` where CX is a value in the sequence.
277    pub where_conds: Where,
278    /// The function body.
279    /// To only declare the function, this must be `;` so use [FunctionBodyDeclare]
280    /// To implement the function, use [FunctionBodyImplement]
281    pub body: Body,
282}
283
284impl<Mods, Name, Args, Return, Where, Body> CanHaveAttributes
285    for FunctionDef<Mods, Name, Args, Return, Where, Body>
286{
287    fn with_attributes<Attr>(self, attr: Attr) -> WithAttributes<Attr, Self> {
288        WithAttributes {
289            attr,
290            separator: "\n",
291            value: self,
292        }
293    }
294}
295
296/// Declares a function body. This is equivalent to just a semicolon.
297#[derive(Clone, Debug)]
298pub struct FunctionBodyDeclare;
299
300/// Implements a function body. Places the contents inside brackets
301#[derive(Clone, Debug)]
302pub struct FunctionBodyImplement<Inner>(pub Inner);
303
304/// A function pointer. Can be used for `fn`, `Fn`, `FnMut`, and `FnOnce`.
305///
306/// Example:
307/// ```
308/// # use async_codegen::common::{SingularSeq, Str};
309/// # use async_codegen::context::EmptyContext;
310/// # use async_codegen::rust::{FunctionPtr, FunctionPtrKind};
311/// # use async_codegen::util::InMemoryOutput;
312/// let function_ptr = FunctionPtr {
313///   kind: FunctionPtrKind::FnMut,
314///   args: SingularSeq(Str("String")),
315///   return_type: Str("bool")
316/// };
317/// let string = InMemoryOutput::print_output(EmptyContext, &function_ptr);
318/// assert_eq!("FnMut(String) -> bool", string);
319/// ```
320#[derive(Clone, Debug)]
321pub struct FunctionPtr<Args, Return> {
322    /// The function pointer kind
323    pub kind: FunctionPtrKind,
324    /// The arguments. Must be a sequence
325    pub args: Args,
326    /// The return type, i.e. after the `->` arrow
327    pub return_type: Return,
328}
329
330/// The kind of function type
331#[derive(Clone, Debug)]
332pub enum FunctionPtrKind {
333    /// An `fn` pointer. E.g. `fn(String) -> bool`.
334    FnPtr,
335    /// Represents [Fn]
336    Fn,
337    /// Represents [FnMut]
338    FnMut,
339    /// Represents [FnOnce]
340    FnOnce,
341}
342
343/// Renders as `Type=Value`. Intended to be used as a type argument, to specify associated types.
344#[derive(Clone, Debug)]
345pub struct AssociatedTypeEquals<Type, Value>(pub Type, pub Value);
346
347/// Adds a "dyn " before a type expression.
348#[derive(Clone, Debug)]
349pub struct DynOf<Type>(pub Type);
350
351/// Adds a "&" before a type expression
352#[derive(Clone, Debug)]
353pub struct RefOf<Type>(pub Type);
354
355/// Adds an "impl " before a type expression
356pub struct ImplOf<Type>(pub Type);
357
358/// Adds a reference with a lifetime before a type expression, i.e. `&'<lifetime> <type>`
359#[derive(Clone, Debug)]
360pub struct LifetimedRefOf<'l, Type>(pub &'l str, pub Type);
361
362/// Declares an associated type, rendering as `type VarName = Value;`.
363/// Adds new lines before and after.
364#[derive(Clone, Debug)]
365pub struct AssociatedTypeDef<VarName, Value>(pub VarName, pub Value);
366
367/// The declaration of a trait
368#[derive(Clone, Debug)]
369pub struct TraitDef<Mods, Name, TypeVars, SuperTraits, Body> {
370    /// The trait modifiers, e.g. visibility. Must be a sequence.
371    pub mods: Mods,
372    /// The name of the trait
373    pub name: Name,
374    /// The type variables. Must be a sequence
375    pub type_variables: TypeVars,
376    /// The super traits. Must be a sequence
377    pub super_traits: SuperTraits,
378    /// The trait definition's body. Use [NoOp] if none exists.
379    pub body: Body,
380}
381
382impl<Mods, Name, TypeVars, SuperTraits, Body> CanHaveAttributes
383    for TraitDef<Mods, Name, TypeVars, SuperTraits, Body>
384{
385    fn with_attributes<Attr>(self, attr: Attr) -> WithAttributes<Attr, Self> {
386        WithAttributes {
387            attr,
388            separator: "\n",
389            value: self,
390        }
391    }
392}
393
394/// The implementation declaration for a trait, applying to a certain receiver.
395#[derive(Clone, Debug)]
396pub struct TraitImpl<TypeVars, Trait, Recv, Where, Body> {
397    /// The type variables to use for the impl block itself. All type variables that appear later
398    /// on the trait or the receiver must be declared here, per Rust language rules.
399    ///
400    /// This field must be a sequence.
401    pub type_variables: TypeVars,
402    /// The trait being implemented
403    pub the_trait: Trait,
404    /// The receiver for which it is implemented
405    pub receiver: Recv,
406    /// The "where" conditions. Must be a sequence. Set to [NoOpSeq] to disable.
407    /// Will render as `where C1, C2, C3, ...` where CX is a value in the sequence.
408    pub where_conds: Where,
409    /// The body. Use [NoOp] if none exists.
410    pub body: Body,
411}
412
413impl<TypeVars, Trait, Recv, Where, Body> CanHaveAttributes
414    for TraitImpl<TypeVars, Trait, Recv, Where, Body>
415{
416    fn with_attributes<Attr>(self, attr: Attr) -> WithAttributes<Attr, Self> {
417        WithAttributes {
418            attr,
419            separator: "\n",
420            value: self,
421        }
422    }
423}
424
425/// The declaration of a struct.
426#[derive(Clone, Debug)]
427pub struct StructDef<Mods, Name, Elements> {
428    /// The struct modifiers. Must be a sequence.
429    pub mods: Mods,
430    /// The kind of the struct.
431    ///
432    /// It is suggested to use either a [NamedTuple] or [StructCall]. A semicolon will be
433    /// automatically added afterward, as is needed for tuple structs, and this semicolon will not
434    /// affect structs with named fields.
435    pub kind: StructKind<Name, Elements>,
436}
437
438impl<Mods, Name, Elements> CanHaveAttributes for StructDef<Mods, Name, Elements> {
439    fn with_attributes<Attr>(self, attr: Attr) -> WithAttributes<Attr, Self> {
440        WithAttributes {
441            attr,
442            separator: "\n",
443            value: self,
444        }
445    }
446}
447
448/// Completes the struct definition as either a named tuple or a struct with named fields.
449#[derive(Clone, Debug)]
450pub enum StructKind<Name, Elements> {
451    /// A named tuple. This will function similarly to [NamedTuple], except a semicolon will
452    /// be added afterward.
453    ///
454    /// `Name` must be writable, and `Elements` must be a writable sequence for the tuple arguments.
455    Tuple(Name, Elements),
456    /// A struct with named fields. This will function similarly to [StructCall].
457    ///
458    /// `Name` must be writable, and `Elements` must be writable sequence for the struct fields.
459    NamedFields(Name, Elements),
460}
461
462/// The construction or deconstruction of a struct.
463///
464/// When rendered, will use the format `Name { Body }`. Spaces will be added automatically.
465///
466/// This should **not** be used for tuple structs, for that see [NamedTuple].
467#[derive(Clone, Debug)]
468pub struct StructCall<Name, Body> {
469    /// The struct name. Must be writable.
470    ///
471    /// If you are declaring a struct for the first time, you can use [Parameterized] in order
472    /// to declare type variables.
473    pub name: Name,
474    /// The body. Must be writable.
475    ///
476    /// It is suggested to use [StructFields] for multiple fields, or [DeclareField] for just one.
477    pub body: Body,
478}
479
480/// Named struct fields. This will place every field on a new line with a comma afterward.
481/// It is recommended that the sequence should pass [DeclareField].
482///
483/// If you have a single field, you can skip using a sequence and just use [DeclareField] directly.
484pub struct StructFields<Fields>(pub Fields);
485
486/// Declares a single field within a struct. Renders as `Name: Value`.
487///
488/// Does not add attributes. If you want to use attributes for declaration purposes, you can use
489/// [CanHaveAttributes::with_attributes] on this field.
490pub struct DeclareField<Name, Value>(pub Name, pub Value);
491
492impl<Name, Value> CanHaveAttributes for DeclareField<Name, Value> {
493    fn with_attributes<Attr>(self, attr: Attr) -> WithAttributes<Attr, Self> {
494        WithAttributes {
495            attr,
496            separator: "\n",
497            value: self,
498        }
499    }
500}
501
502/// A named tuple type.
503///
504/// Renders as `Name(A1, A2, A3, ...)` where AX is part of the argument sequence.
505/// If no arguments exist, will render only as `Name` (i.e., a unit struct).
506pub struct NamedTuple<Name, Args> {
507    pub name: Name,
508    pub args: Args,
509}
510
511/// An anonymous tuple type. This struct's tuple value must be a sequence.
512///
513/// Renders as `(A1, A2, A3, ...)` where AX is part of the argument sequence.
514#[derive(Clone, Debug)]
515pub struct AnonTuple<Args>(pub Args);
516
517/// The unit type, i.e. `()`
518pub type UnitType = AnonTuple<NoOpSeq>;
519
520impl AnonTuple<NoOpSeq> {
521    /// Creates
522    pub fn unit() -> Self {
523        Self(NoOpSeq)
524    }
525}
526
527/// Adds attributes to ANY item.
528///
529/// The first tuple value must be a sequence. The second must be a writable value. This struct
530/// is typically constructed via [CanHaveAttributes::with_attributes].
531///
532/// Rust attributes can be put in many places, so this enables you to add attributes to any
533/// writable item. For example, adding attributes to function parameters can be done like so:
534///
535/// ```rust
536/// # use async_codegen::common::{SingularSeq, Str};
537/// # use async_codegen::context::EmptyContext;
538/// # use async_codegen::rust::{Cfg, FunctionParam, MustUse, Target, WithAttributes, CanHaveAttributes};
539/// # use async_codegen::util::InMemoryOutput;
540///
541/// let function_param = FunctionParam(Str("conditional_param"), Str("Fd")).with_attributes(
542///   SingularSeq(Cfg(Target::Os(Str("linux"))))
543/// );
544/// let string = InMemoryOutput::print_output(EmptyContext, &function_param);
545/// assert_eq!("#[cfg(target_os = \"linux\")] conditional_param: Fd", string);
546/// ```
547#[derive(Clone, Debug)]
548pub struct WithAttributes<Attr, Value> {
549    pub attr: Attr,
550    /// The separator. Usually a space or a new line, depending on what the target value is
551    pub separator: &'static str,
552    /// The value
553    pub value: Value,
554}
555
556/// A writable that can have attributes attached to it
557pub trait CanHaveAttributes: Sized {
558    /// Adds attributes to this writable
559    fn with_attributes<Attr>(self, attr: Attr) -> WithAttributes<Attr, Self>;
560}
561
562/// Defines an enum.
563///
564/// In order to use or refer to an enum, you can use [AssociatedItem] together with [NamedTuple]
565/// or [StructCall].
566pub struct EnumDef<Mods, Name, Entries> {
567    /// The modifiers on the type. Must be a sequence.
568    pub mods: Mods,
569    /// The name of the enum
570    pub name: Name,
571    /// The enum entries. Must be a sequence, each entry will be written on a new line with a comma
572    ///
573    /// As for the entries themselves, it is suggested to use [NamedTuple] or [StructCall]
574    /// depending on which kind of enum entry you want to create.
575    pub entries: Entries,
576}
577
578impl<Mods, Name, Entries> CanHaveAttributes for EnumDef<Mods, Name, Entries> {
579    fn with_attributes<Attr>(self, attr: Attr) -> WithAttributes<Attr, Self> {
580        WithAttributes {
581            attr,
582            separator: "\n",
583            value: self,
584        }
585    }
586}
587
588/// A type argument-parameterized expression. Used in relation to parameterized names and their
589/// arguments. Examples: `function_name<args>`, `TypeName<'lifetime, args>`, `MyType<Assoc=Value>`.
590///
591/// If no type args exist, [NoOpSeq] should be used.
592#[derive(Clone, Debug)]
593pub struct Parameterized<Name, TypeArgs> {
594    name: Name,
595    type_args: TypeArgs,
596}
597
598impl<Name, TypeArgs> Parameterized<Name, TypeArgs> {
599    /// Initializes an instance
600    pub fn new(name: Name, type_args: TypeArgs) -> Self {
601        Self { name, type_args }
602    }
603}
604
605/// A type variable with a sequence of bounds.
606/// Will render as `TypeVar: B1 + B2 + ...`
607#[derive(Clone, Debug)]
608pub struct BoundedTypeVar<TypeVar, Bounds>(pub TypeVar, pub Bounds);
609
610/// A standalone lifetime, intended to be used as a type argument or variable
611#[derive(Clone, Debug)]
612pub struct Lifetime<'l>(pub &'l str);
613
614/// Renders an individual function parameter, `Name: Type`
615#[derive(Clone, Debug)]
616pub struct FunctionParam<Name, Type>(pub Name, pub Type);
617
618impl<Name, Type> CanHaveAttributes for FunctionParam<Name, Type> {
619    fn with_attributes<Attr>(self, attr: Attr) -> WithAttributes<Attr, Self> {
620        WithAttributes {
621            attr,
622            separator: " ",
623            value: self,
624        }
625    }
626}
627
628/// A sequence acceptor that writes attributes. Every attribute will be surrounded with "#[]"
629#[derive(Debug)]
630pub struct AttributesAccept<'o, O, Sep> {
631    inner: SurroundingSeqAccept<'o, O, Str<&'static str>, Combined<Str<&'static str>, Sep>>,
632}
633
634impl<'o, O> AttributesAccept<'o, O, Str<&'static str>> {
635    pub fn multiline(output: &'o mut O) -> Self {
636        Self::with_separator(output, "\n")
637    }
638}
639
640impl<'o, O> AttributesAccept<'o, O, Str<&'static str>> {
641    pub fn with_separator(output: &'o mut O, separator: &'static str) -> Self {
642        Self {
643            inner: SurroundingSeqAccept::new(output, Str("#["), Combined(Str("]"), Str(separator))),
644        }
645    }
646}
647
648impl<'o, O, Sep> SequenceAccept<O> for AttributesAccept<'o, O, Sep>
649where
650    O: Output,
651    Sep: Writable<O>,
652{
653    async fn accept<W: Writable<O>>(&mut self, writable: &W) -> Result<(), O::Error> {
654        self.inner.accept(writable).await
655    }
656}