MCPcopy Create free account
hub / github.com/devashishdxt/cli-table / table

Function table

cli-table-derive/src/table.rs:7–115  ·  view source on GitHub ↗
(input: DeriveInput)

Source from the content-addressed store, hash-verified

5use crate::context::Context;
6
7pub fn table(input: DeriveInput) -> Result<TokenStream> {
8 // Create context for generating expressions
9 let context = Context::new(&input)?;
10
11 // Used in the quasi-quotation below as `#name`
12 let name = context.container.name;
13
14 // Fetch cli_table crate name
15 let cli_table = &context.container.crate_name;
16
17 // Split a type's generics into the pieces required for implementing a trait for that type
18 let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
19
20 let mut field_titles = Vec::new();
21 let mut field_rows = Vec::new();
22
23 for field in context.fields.into_iter() {
24 field_titles.push(field.title);
25
26 let ident = field.ident;
27 let justify = field.justify;
28 let align = field.align;
29 let color = field.color;
30 let bold = field.bold;
31 let display_fn = field.display_fn;
32 let customize_fn = field.customize_fn;
33 let span = field.span;
34
35 let cell = match display_fn {
36 None => quote_spanned! {span=>
37 &self. #ident
38 },
39 Some(display_fn) => {
40 let span = display_fn.span();
41 quote_spanned! {span=>
42 #display_fn (&self. #ident)
43 }
44 }
45 };
46
47 let mut row = quote_spanned! {span=>
48 #cli_table ::Cell::cell(#cell)
49 };
50
51 if let Some(justify) = justify {
52 row = quote_spanned! {span=>
53 #row .justify(#justify)
54 };
55 }
56
57 if let Some(align) = align {
58 row = quote_spanned! {span=>
59 #row .align(#align)
60 };
61 }
62
63 if let Some(color) = color {
64 row = quote_spanned! {span=>

Callers

nothing calls this directly

Calls 2

into_iterMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected