ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
//! The MUTATION NODE's ASSEMBLED FACE: one function that is the whole of what a node can be told,
//! and the two sums that are what it answers with.
//!
//! ```ignore
//! impl WatchOps {
//!   async fn handle_watch_ops(
//!     catalog: &crate::Catalog,
//!     cmd: WatchOpsCommand,
//!   ) -> Result<WatchOpsResponse, WatchOpsError>;
//! }
//! ```
//!
//! # THE MODE IS THE OR OF ITS HANDLERS', which is what `ALL_SYNC` was recorded for
//!
//! A node whose every handler is blocking assembles into a BLOCKING function, and one awaited
//! handler makes the whole face awaited. So a deployment that controls a wholly synchronous node
//! needs no runtime to say anything to it — which is the dividend, and the reason the law is an OR
//! rather than *always async*: an awaited face is the more general shape and the more expensive one,
//! and paying for it where nothing awaits would be the framework choosing a runtime on an
//! application's behalf.
//!
//! | the node's handlers | `ALL_SYNC` | the assembled face |
//! |---|---|---|
//! | every one blocking | `true` | `fn handle_…` |
//! | at least one awaited | `false` | `async fn handle_…` |
//!
//! # IT IS THE TOTAL CAPABILITY, and the WIRE stays per-field
//!
//! The binding emits one root field per exchange and calls that exchange's own handler — the shape
//! that makes *answering the wrong command* unwritable rather than guarded. Nothing about that
//! changes here, and the two sums below never appear in a schema. What this face is for is every
//! OTHER caller of a node: a first-party RPC or framework binding that has a command in hand and
//! wants one door, a test that drives a node without a schema, and the source-side caller that holds
//! a `<Node>Command` off its own `Control` line and wants to run it.
//!
//! So the node-level `Response` and `Error` sums — retired from the wire face, where per-field
//! answering deleted them — are REVIVED here as this face's return vocabulary. They are the same
//! types the retirement ledger named, in the one position that still has a use for them.
//!
//! # THE ERROR SUM IS HONESTLY EMPTY, and that is a real answer
//!
//! An arm per FALLIBLE exchange and none for the others: a `Never`-tier exchange contributes no way
//! to fail, so a node whose every exchange is that tier gets an error sum with no variants at all.
//! `Result<_, WatchOpsError>` is then a `Result` whose `Err` has no values — the same claim `()`'s
//! `Infallible` command makes one seat over, and the same total-capability-and-honest-empty pattern.
//!
//! # ONE CALL SITE CASTS THE THREE-TIER SIGNATURE, and both faces spend it
//!
//! Each exchange gets a hidden [`ExchangeModel::call_name`] function on the node — the ONE place a
//! handler is called at the exact signature its `error(…)` word chose, spanned at the `handler` path
//! word. The wire's resolver calls it, and so does the arm of this face.
//!
//! A second, independent cast would have been the obvious way to write this face, and it is the one
//! thing this module must not do: a handler whose body does not match its declaration would then be
//! reported TWICE, at two sites, about one mistake — and the corpus that pins *the refusal lands on
//! the word that chose it* would be pinning it twice over. One fact, one account.

use proc_macro2::TokenStream;
use quote::{ToTokens as _, format_ident, quote, quote_spanned};
use syn::spanned::Spanned as _;

use super::{DeclaredError, ExchangeModel, MutationModel};

#[cfg(test)]
mod tests;

impl MutationModel {
  /// The response sum's name — the node's own, with `Response` after it.
  ///
  /// Derived rather than declared, for [`command_name`](Self::command_name)'s reason: the node's
  /// name IS the vocabulary's name, and a second word for it would be a name two spellings could
  /// disagree about.
  #[must_use]
  pub fn response_name(&self) -> syn::Ident {
    format_ident!("{}Response", self.name)
  }

  /// The error sum's name — the node's own, with `Error` after it.
  #[must_use]
  pub fn error_name(&self) -> syn::Ident {
    format_ident!("{}Error", self.name)
  }

  /// The assembled face's name — `handle_` and the node's own name in snake case.
  ///
  /// Named after the NODE and not numbered, which is the ruling: a position in a list is a name that
  /// moves when the list is reordered, and the node is what the face is the capability of.
  #[must_use]
  pub fn face_name(&self) -> syn::Ident {
    format_ident!("handle_{}", crate::emit::snake(&self.name.to_string()))
  }

  /// Whether the assembled face is awaited — the OR law, read off the declaration.
  #[must_use]
  pub fn awaited(&self) -> bool {
    !self.all_sync()
  }

  /// The whole assembled surface: the two sums, the per-exchange calls, and the face over them.
  pub(super) fn assembly(&self) -> TokenStream {
    let response = self.response();
    let error = self.error();
    let rendering = self.rendering();
    let calls = self.calls();
    let assembled = self.assembled();
    quote! {
      #response
      #error
      #rendering
      #calls
      #assembled
    }
  }

  /// THE RESPONSE SUM: one arm per exchange, carrying that exchange's own answer.
  ///
  /// The payload is the PROJECTION `<Ty as Mutation>::Response`, exactly as the command enum's is a
  /// projection of `Request` — so this emission is the same assert one seat over, and a `()` answer
  /// is a `()` payload. The wire's `Boolean!` rendering has no business here: that is a RENDERING
  /// for a schema position that must publish something, and this face answers in Rust.
  fn response(&self) -> TokenStream {
    let krate = &self.krate;
    let vis = &self.vis;
    let name = self.response_name();
    let arms = self.exchanges.iter().map(|exchange| {
      let variant = exchange.variant();
      let ty = &exchange.ty;
      let doc = crate::emit::leading(&format!(
        "What the `{field}` exchange answered.",
        field = exchange.named(),
      ));
      quote! {
        #[doc = #doc]
        #variant(<#ty as #krate::__private::source::Mutation>::Response)
      }
    });
    let doc = crate::emit::leading(&format!(
      "What [`{node}`]'s assembled face answers with — one arm per exchange it declared.\n\nThe \
       node-level response sum, revived: the WIRE answers per field and never through this type, \
       and what it serves is every other caller of \
       [`{node}::{face}`]({node}::{face}).",
      node = self.name,
      face = self.face_name(),
    ));
    // PAYLOAD-BLIND, for the reason the error sum's own is: a derive would put a `Debug` bound on
    // every declared response type, and the origin layer's discipline is *arity and never the
    // payload*. It is written at all — where the COMMAND enum has none — because this is what comes
    // BACK: a caller already holds what it sent, and what it is handed is what it inspects.
    let debugged = self.exchanges.iter().map(|exchange| {
      let variant = exchange.variant();
      let printed = variant.to_string();
      quote!(Self::#variant(_) => ::core::fmt::Formatter::write_str(__ingraph_f, #printed))
    });
    let debug = if self.exchanges.is_empty() {
      quote!(match *self {})
    } else {
      quote!(match self { #(#debugged,)* })
    };
    quote! {
      #[doc = #doc]
      #vis enum #name {
        #(#arms),*
      }

      impl ::core::fmt::Debug for #name {
        fn fmt(&self, __ingraph_f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
          #debug
        }
      }
    }
  }

  /// THE ERROR SUM: one arm per FALLIBLE exchange, and none at all for a node that cannot fail.
  ///
  /// A `Rich` exchange's arm carries the type its declaration named; a `Canned` one carries nothing,
  /// because a canned failure's whole content — the sentence and the heading — lives in the
  /// declaration and the handler reports only the position it failed at.
  fn error(&self) -> TokenStream {
    let vis = &self.vis;
    let name = self.error_name();
    let arms = self.fallible().map(|exchange| {
      let variant = exchange.variant();
      let doc = crate::emit::leading(&format!(
        "The `{field}` exchange refused.",
        field = exchange.named(),
      ));
      let payload = match &exchange.handler.error {
        Some(DeclaredError::Rich { ty, .. }) => quote!((#ty)),
        // A canned failure carries no value: `Err(())` is a POSITION, and the words are the
        // declaration's — which is what the `Display` below renders.
        _ => TokenStream::new(),
      };
      quote! {
        #[doc = #doc]
        #variant #payload
      }
    });
    let doc = crate::emit::leading(&format!(
      "How [`{node}`]'s assembled face refuses — one arm per exchange that declared a failure.\n\nA \
       node whose every exchange is the `Never` tier gets an enum with NO variants, which is the \
       honest answer rather than an omission: there is no way for such a node to fail, so there is \
       no value of this type.",
      node = self.name,
    ));
    quote! {
      #[doc = #doc]
      #vis enum #name {
        #(#arms),*
      }
    }
  }

  /// The error sum's own faces: what it prints, what it debugs as, that it IS an error, and the
  /// heading its declaration wrote.
  ///
  /// # `Display` is the ONE-CODE-HEAD LAW, spelled here as the binding spells it
  ///
  /// A declared `code` heads the rendering and the failure's own words follow it, which is exactly
  /// what `refused_exchange` does at the wire. So the same failure reads the same way through either
  /// face — and a declaration that heads a failure whose own `Display` already carries a heading
  /// publishes two, which is why the `code` word is omitted for such a type. See the macro's own doc.
  ///
  /// # `Debug` is HAND-WRITTEN and payload-blind, which is what keeps it free
  ///
  /// A derive would put a `Debug` bound on every declared error type. The origin layer's own debug
  /// discipline is *arity and never the payload* — the same reason the command enum derives nothing
  /// — so the arm's NAME is printed and the value inside it is reached by matching. The one bound
  /// this whole emission does place is `Display` on a `Rich` failure, and that one the `code` word
  /// already presupposed: a heading heads something a reader can read.
  fn rendering(&self) -> TokenStream {
    let name = self.error_name();
    let empty = self.fallible().next().is_none();
    // An UNINHABITED sum is matched through the place rather than through arms: there is no value,
    // so there is no arm to write, and `match *self {}` is the compiler's own proof of it.
    let (display, debug, code) = if empty {
      (
        quote!(match *self {}),
        quote!(match *self {}),
        quote!(match *self {}),
      )
    } else {
      let displayed = self.fallible().map(|exchange| exchange.displayed());
      let debugged = self.fallible().map(|exchange| {
        let variant = exchange.variant();
        let printed = variant.to_string();
        let bound = exchange.binds_a_payload().then(|| quote!((_)));
        quote!(Self::#variant #bound => ::core::fmt::Formatter::write_str(__ingraph_f, #printed))
      });
      let coded = self.fallible().map(|exchange| {
        let variant = exchange.variant();
        let bound = exchange.binds_a_payload().then(|| quote!((_)));
        let word = match exchange.declared_code() {
          Some(code) => quote!(::core::option::Option::Some(#code)),
          None => quote!(::core::option::Option::None),
        };
        quote!(Self::#variant #bound => #word)
      });
      (
        quote!(match self { #(#displayed,)* }),
        quote!(match self { #(#debugged,)* }),
        quote!(match self { #(#coded,)* }),
      )
    };
    let doc = crate::emit::leading(
      "The heading this failure renders under, where its declaration wrote a `code` word.\n\nThe \
       same fact `Fallibility::code` carries in the declaration record, reachable from the value \
       itself — which is what a caller mapping this sum onto a transport's own vocabulary needs.",
    );
    quote! {
      impl ::core::fmt::Display for #name {
        fn fmt(&self, __ingraph_f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
          #display
        }
      }

      impl ::core::fmt::Debug for #name {
        fn fmt(&self, __ingraph_f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
          #debug
        }
      }

      impl ::core::error::Error for #name {}

      impl #name {
        #[doc = #doc]
        #[must_use]
        pub const fn code(&self) -> ::core::option::Option<&'static str> {
          #code
        }
      }
    }
  }

  /// THE ONE CAST SITE per exchange — see the module note for why there is exactly one.
  fn calls(&self) -> TokenStream {
    let name = &self.name;
    let calls = self.exchanges.iter().map(|exchange| exchange.call(self));
    quote! {
      impl #name {
        #(#calls)*
      }
    }
  }

  /// THE ASSEMBLED FACE itself: the grants its exchanges were granted, the command, and the two sums.
  fn assembled(&self) -> TokenStream {
    let vis = &self.vis;
    let name = &self.name;
    let face = self.face_name();
    let command = self.command_name();
    let response = self.response_name();
    let error = self.error_name();
    let granted = self.granted();
    let parameters = granted
      .iter()
      .map(|(held, resource)| quote!(#held: &#resource));
    let awaited = self.awaited().then(|| quote!(async));
    let arms = self
      .exchanges
      .iter()
      .map(|exchange| exchange.arm(self, &granted));
    // An UNINHABITED command is matched through the place, exactly as the empty error sum is: a node
    // that declared no exchange has nothing that can be said to it, and no arm to write.
    let body = if self.exchanges.is_empty() {
      quote!(match __ingraph_cmd {})
    } else {
      quote!(match __ingraph_cmd { #(#arms)* })
    };
    let doc = crate::emit::leading(&format!(
      "Run whatever this node was told — [`{node}`]'s TOTAL CAPABILITY, in one \
       {face_kind}function.\n\nOne arm per declared exchange, each calling that exchange's own \
       handler at the signature its `error(…)` word chose. The face is {face_kind}because \
       `ALL_SYNC` is `{all_sync}` — the OR law: a node whose every handler is blocking assembles \
       into a blocking function, and one awaited handler makes the whole face awaited.\n\nThe WIRE \
       does not come through here. A schema publishes one root field per exchange and calls that \
       exchange's handler directly; what this serves is every other caller — a first-party \
       transport, a test, and the source-side party holding a command off its own `Control` \
       line.\n\n# Errors\n\nWhichever of [`{error}`]({error})'s arms the exchange that ran declared.",
      node = self.name,
      face_kind = if self.awaited() {
        "awaited "
      } else {
        "blocking "
      },
      all_sync = self.all_sync(),
    ));
    quote! {
      impl #name {
        #[doc = #doc]
        #vis #awaited fn #face(
          #(#parameters,)*
          __ingraph_cmd: #command,
        ) -> ::core::result::Result<#response, #error> {
          #body
        }
      }
    }
  }

  /// Every exchange that declared a failure, in declaration order — the error sum's arms.
  fn fallible(&self) -> impl Iterator<Item = &ExchangeModel> {
    self
      .exchanges
      .iter()
      .filter(|exchange| exchange.handler.error.is_some())
  }

  /// The RESOURCES this node's handlers were granted, deduplicated, in first-written order — the
  /// assembled face's own parameter list.
  ///
  /// One face runs every exchange, so it is handed the UNION of what they were granted: a caller
  /// holding a command does not know which arm it will take, and a signature that varied by arm
  /// would not be one function.
  ///
  /// The key is the path AS WRITTEN. Two spellings of one type — an alias, a re-export — are two
  /// parameters here, which is the honest answer for a pass that resolves nothing: this emission
  /// cannot know they meet, and guessing that they do would be it deciding a question the compiler
  /// owns.
  fn granted(&self) -> Vec<(syn::Ident, syn::Path)> {
    // `cmd` is seeded, so a resource whose name would collide with the command parameter takes the
    // suffixed spelling instead of shadowing it.
    let mut taken: Vec<String> = vec!["cmd".to_owned()];
    let mut granted: Vec<(syn::Ident, syn::Path)> = Vec::new();
    for resource in self
      .exchanges
      .iter()
      .flat_map(|exchange| &exchange.handler.context)
    {
      if granted
        .iter()
        .any(|(_, held)| super::path_word(held) == super::path_word(resource))
      {
        continue;
      }
      let bare = resource.segments.last().map_or_else(
        || "granted".to_owned(),
        |segment| crate::emit::snake(&segment.ident.to_string()),
      );
      let mut held = bare.clone();
      let mut at = 1;
      while taken.contains(&held) {
        held = format!("{bare}_{at}");
        at += 1;
      }
      taken.push(held.clone());
      granted.push((format_ident!("{held}"), resource.clone()));
    }
    granted
  }
}

impl ExchangeModel {
  /// The hidden function that CALLS this exchange's handler — the one place its three-tier signature
  /// is cast.
  #[must_use]
  pub fn call_name(&self) -> syn::Ident {
    format_ident!("__ingraph_exchange_{}", self.named())
  }

  /// Whether this exchange's error-sum arm carries a value — `Rich` and nothing else.
  fn binds_a_payload(&self) -> bool {
    matches!(&self.handler.error, Some(DeclaredError::Rich { .. }))
  }

  /// The `code = "…"` word this exchange's failure was headed with, where one was written.
  fn declared_code(&self) -> Option<&syn::LitStr> {
    match &self.handler.error {
      Some(DeclaredError::Rich { code, .. } | DeclaredError::Canned { code, .. }) => code.as_ref(),
      None => None,
    }
  }

  /// This exchange's arm of the error sum's `Display` — the one-code-head law, one arm at a time.
  fn displayed(&self) -> TokenStream {
    let variant = self.variant();
    let head = self.declared_code().map(|code| {
      let head = format!("{code}: ", code = code.value());
      quote!(::core::fmt::Formatter::write_str(__ingraph_f, #head)?;)
    });
    match &self.handler.error {
      // The RICH failure's words are the value's own, so the heading is written and the value
      // renders itself — which is exactly what the wire's own renderer does with the same pair.
      Some(DeclaredError::Rich { .. }) => quote! {
        Self::#variant(__ingraph_refusal) => {
          #head
          ::core::fmt::Display::fmt(__ingraph_refusal, __ingraph_f)
        }
      },
      // The CANNED failure's whole rendering is fixed at the declaration, so it is ONE literal:
      // there is nothing at runtime that could vary it.
      Some(DeclaredError::Canned { message, code }) => {
        let sentence = match code {
          Some(code) => format!(
            "{code}: {message}",
            code = code.value(),
            message = message.value()
          ),
          None => message.value(),
        };
        quote!(Self::#variant => ::core::fmt::Formatter::write_str(__ingraph_f, #sentence))
      }
      None => TokenStream::new(),
    }
  }

  /// The hidden call — this exchange's handler, at the exact signature its declaration chose.
  ///
  /// The CAST is a `let` with the tier written on it rather than the function's return type alone,
  /// and the difference is the diagnostic: an annotated binding reports a mismatched body at the
  /// call — which is spanned at the `handler` path word — and says *expected `…`, found `…`* about
  /// the two types the declaration and the body disagree on.
  fn call(&self, model: &MutationModel) -> TokenStream {
    let krate = &model.krate;
    let mutation = crate::emit::framework(krate, &["source"], "Mutation");
    let ty = &self.ty;
    let name = self.call_name();
    let path = &self.handler.path;

    let granted: Vec<syn::Ident> = (0..self.handler.context.len())
      .map(|at| format_ident!("__ingraph_granted_{at}"))
      .collect();
    let parameters = granted
      .iter()
      .zip(&self.handler.context)
      .map(|(held, resource)| quote!(#held: &#resource));
    let awaited = self.handler.awaited.then(|| quote!(.await));
    let face = self.handler.awaited.then(|| quote!(async));
    let call = quote_spanned! {path.span()=>
      #path(#(#granted,)* __ingraph_request) #awaited
    };

    let tier = match &self.handler.error {
      None => quote!(<#ty as #mutation>::Response),
      Some(DeclaredError::Rich { ty: failure, .. }) => {
        let failure = failure.to_token_stream();
        quote!(::core::result::Result<<#ty as #mutation>::Response, #failure>)
      }
      Some(DeclaredError::Canned { .. }) => {
        quote!(::core::result::Result<<#ty as #mutation>::Response, ()>)
      }
    };
    let doc = crate::emit::leading(&format!(
      "The `{field}` exchange's handler, called at the signature its declaration chose.\n\nHidden, \
       and there is exactly ONE of it: the wire's resolver and the assembled face both spend this \
       call, so a body that wears another signature is refused once, at the `handler` word.",
      field = self.named(),
    ));
    quote! {
      #[doc = #doc]
      #[doc(hidden)]
      #face fn #name(
        #(#parameters,)*
        __ingraph_request: <#ty as #mutation>::Request,
      ) -> #tier {
        let __ingraph_outcome: #tier = #call;
        __ingraph_outcome
      }
    }
  }

  /// This exchange's arm of the assembled face.
  fn arm(&self, model: &MutationModel, granted: &[(syn::Ident, syn::Path)]) -> TokenStream {
    let command = model.command_name();
    let response = model.response_name();
    let error = model.error_name();
    let variant = self.variant();
    let call = self.call_name();
    // The grants this exchange asked for, taken out of the face's own parameters BY THE PATH THAT
    // NAMED THEM — the same key the union was built under.
    let arguments = self.handler.context.iter().map(|resource| {
      granted
        .iter()
        .find(|(_, held)| super::path_word(held) == super::path_word(resource))
        .map_or_else(|| quote!(#resource), |(held, _)| quote!(#held))
    });
    let awaited = self.handler.awaited.then(|| quote!(.await));
    let ran = quote!(Self::#call(#(#arguments,)* __ingraph_request) #awaited);

    match &self.handler.error {
      None => quote! {
        #command::#variant(__ingraph_request) => ::core::result::Result::Ok(
          #response::#variant(#ran)
        ),
      },
      Some(DeclaredError::Rich { .. }) => quote! {
        #command::#variant(__ingraph_request) => match #ran {
          ::core::result::Result::Ok(__ingraph_answer) =>
            ::core::result::Result::Ok(#response::#variant(__ingraph_answer)),
          ::core::result::Result::Err(__ingraph_refusal) =>
            ::core::result::Result::Err(#error::#variant(__ingraph_refusal)),
        },
      },
      Some(DeclaredError::Canned { .. }) => quote! {
        #command::#variant(__ingraph_request) => match #ran {
          ::core::result::Result::Ok(__ingraph_answer) =>
            ::core::result::Result::Ok(#response::#variant(__ingraph_answer)),
          // The canned failure's `Err(())` is read for its POSITION and nothing else — the words are
          // the declaration's, and the arm below is where they are rendered from.
          ::core::result::Result::Err(()) =>
            ::core::result::Result::Err(#error::#variant),
        },
      },
    }
  }
}