ferri-pdf 0.1.3

HTML and CSS to PDF renderer for print, in pure Rust
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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
//! Block measurement, page fragmentation, and positioned text fragments.
mod anchors;
mod breaks;
mod flex;
mod float_area;
mod floats;
mod geometry;
mod grid;
mod images;
mod inline;
mod intrinsic;
mod margin;
mod markers;
mod mathml;
mod measure;
mod motion;
mod multicol;
mod navigation;
mod page_counters;
mod page_margins;
mod page_output;
mod page_paint;
mod pagination;
mod physical_pages;
mod positioned;
mod ratio;
mod source;
mod sticky;
mod strings;
mod tables;
mod viewport;
mod work;
mod writing;
use crate::document::StyledDocument;
use crate::fonts::FontDescriptor;
use crate::graphics::{Color, DisplayItem, Rect};
use crate::resources::ResourceResolver;
use crate::text::{GlyphRun, TextContext, TextError};
use serde::Serialize;

pub use navigation::{Destination, HeadingLocation, LinkArea, LinkShape};
pub(crate) use page_output::{PageOutput, PageRecord};
pub(crate) use viewport::ViewportPaint;

pub(crate) const MAX_LAYOUT_PAGES: usize = 10_000;
/// Aggregate layout-work units per job, shared by measurement and pagination probes.
/// Units count source visits, text bytes, grid slots and solver candidate items.
/// Exhaustion returns [`LayoutError::WorkLimit`]; this is not a time or memory limit.
pub(crate) const MAX_LAYOUT_WORK: usize = 100_000_000;

#[derive(Clone, Debug, Serialize)]
pub struct TextLine {
    pub paragraph: usize,
    pub text: String,
    pub x: f32,
    pub baseline: f32,
    pub width: f32,
    pub height: f32,
    pub runs: Vec<GlyphRun>,
    pub font_size: f32,
    pub color: Color,
}

/// The elements whose renderings `element()` images show, the document's root element, and
/// the renderings of those shown outside the document's flow, in footnote areas and
/// page-margin boxes; the last layout's renderings and the alpha its floats sampled of them,
/// and the alpha this layout's floats sample.
#[derive(Default)]
pub(crate) struct ElementTargets {
    pub targets: std::collections::HashSet<crate::dom::ElementId>,
    pub root: Option<crate::dom::ElementId>,
    pub displayed: std::cell::RefCell<pagination::Renderings>,
    pub previous: ElementRenderings,
    pub shapes: crate::document::ShapeSamples,
    pub sampled: std::cell::RefCell<crate::document::ShapeSamples>,
}
impl ElementTargets {
    /// The alpha of the last layout's rendering of `element` stretched over `samples` pixels,
    /// which a float's `shape-outside` reads (CSS Shapes 1 §6.1).
    pub(crate) fn alpha(
        &self,
        element: crate::dom::ElementId,
        samples: [usize; 2],
    ) -> Result<std::sync::Arc<[u8]>, LayoutError> {
        let key = (element, samples);
        let alpha = match self.shapes.get(&key) {
            Some(alpha) => alpha.clone(),
            None => crate::writer::rendering_alpha(element, samples, &self.previous)
                .map_err(|error| LayoutError::Raster(Box::new(error)))?
                .into(),
        };
        self.sampled.borrow_mut().insert(key, alpha.clone());
        Ok(alpha)
    }
}

impl TextLine {
    /// The line drawn with every colour opaque, so that it draws the geometry of its text.
    pub(crate) fn opaque(mut self) -> Self {
        self.color.alpha = Color::BLACK.alpha;
        self.runs = self.runs.into_iter().map(GlyphRun::opaque).collect();
        self
    }
}

#[derive(Serialize)]
pub struct LayoutTrace {
    pub page_width: f32,
    pub page_height: f32,
    /// Page content area and positioning area of document `fixed` backgrounds.
    pub page_area: Rect,
    pub page_output: PageOutput,
    pub page_records: Vec<PageRecord>,
    pub pages: Vec<Vec<TextLine>>,
    pub fonts: Vec<FontDescriptor>,
    pub display_lists: Vec<Vec<DisplayItem>>,
    /// Hyperlink activation areas of each page.
    pub links: Vec<Vec<LinkArea>>,
    /// Where each of the document's destinations is, if its element has a box.
    pub destinations: Vec<Option<Destination>>,
    /// The renderings of the elements that `element()` images show (CSS Images 4 §2.7).
    #[serde(skip)]
    pub(crate) element_images: Box<ElementRenderings>,
}

/// The renderings of the elements that `element()` images show, by element. Layouts of
/// nested navigables stack, so their frames hold these boxed.
pub(crate) type ElementRenderings =
    std::collections::HashMap<crate::dom::ElementId, std::sync::Arc<ViewportPaint>>;

/// Resolves layout without replacing the caller's formatting or navigation metadata.
/// Use `layout_document` when serializing navigation with the resolved trace.
#[cfg(test)]
pub(crate) fn layout(
    document: &StyledDocument,
    resolver: &dyn ResourceResolver,
) -> Result<LayoutTrace, LayoutError> {
    let budget = work::Budget::new(MAX_LAYOUT_WORK);
    let LayoutPass {
        trace,
        generated,
        container_sizes,
        anchor_frames,
        elements,
    } = layout_pass(document, resolver, budget.clone())?;
    let settled = document.styles().query_sizes().settled(&container_sizes)
        && document.styles().anchor_frames().settled(&anchor_frames)
        && document.element_images().settled(&elements);
    if generated.is_none() && settled {
        return Ok(trace);
    }
    let values = generated.unwrap_or_else(|| document.generated_values());
    budget.spend(1)?;
    let mut owned =
        document.fork_for_layout(values.clone(), container_sizes, anchor_frames, resolver)?;
    if !document.element_images().settled(&elements) {
        owned.measured_elements(elements, trace.element_images.clone());
        owned.reformat(values.clone(), resolver)?;
    }
    stabilize(&mut owned, resolver, &budget, vec![values])
}

pub(crate) fn layout_document(
    mut document: StyledDocument,
    resolver: &dyn ResourceResolver,
) -> Result<(StyledDocument, LayoutTrace), LayoutError> {
    let trace = stabilize(
        &mut document,
        resolver,
        &work::Budget::new(MAX_LAYOUT_WORK),
        Vec::new(),
    )?;
    Ok((document, trace))
}

struct LayoutPass {
    trace: LayoutTrace,
    generated: Option<crate::document::GeneratedValues>,
    /// The content-box size each query container measured.
    container_sizes: std::collections::HashMap<crate::dom::ElementId, [f32; 2]>,
    anchor_frames: crate::style::anchor_values::AnchorFrameMap,
    /// What the layout measured of the elements that `element()` images show.
    elements: Box<crate::document::ElementMeasurements>,
}

fn stabilize(
    document: &mut StyledDocument,
    resolver: &dyn ResourceResolver,
    budget: &work::Budget,
    mut previous: Vec<crate::document::GeneratedValues>,
) -> Result<LayoutTrace, LayoutError> {
    let mut measured_sizes = Vec::new();
    let mut measured_anchors = Vec::new();
    let mut measured_elements = Vec::new();
    loop {
        let LayoutPass {
            trace,
            generated,
            container_sizes,
            anchor_frames,
            elements,
        } = layout_pass(document, resolver, budget.clone())?;
        // CSS Conditional 5 §5: each container's descendants are styled with the size of
        // the container they query, so the styles stand once a layout reproduces every size
        // they consulted.
        let containers_settled = document.styles().query_sizes().settled(&container_sizes);
        let anchors_settled = document.styles().anchor_frames().settled(&anchor_frames);
        // CSS Images 4 §2.7: `element()` images resolve against the elements a layout
        // rendered, so they stand once a layout reproduces every rendering they consulted.
        let elements_settled = document.element_images().settled(&elements);
        let settled = containers_settled && anchors_settled && elements_settled;
        let values = match generated {
            None if settled => return Ok(trace),
            None => document.generated_values(),
            Some(values) => {
                if settled && previous.contains(&values) {
                    return Err(LayoutError::GeneratedContentCycle);
                }
                previous.push(values.clone());
                values
            }
        };
        if !containers_settled {
            if measured_sizes.contains(&container_sizes) {
                return Err(LayoutError::ContainerQueryCycle);
            }
            measured_sizes.push(container_sizes.clone());
            document.measured_containers(container_sizes);
        }
        if !anchors_settled {
            if measured_anchors.contains(&anchor_frames) {
                return Err(LayoutError::AnchorPositioningCycle);
            }
            measured_anchors.push(anchor_frames.clone());
            document.measured_anchors(anchor_frames);
        }
        if !elements_settled {
            if measured_elements.contains(&elements) {
                return Err(LayoutError::ElementImageCycle);
            }
            measured_elements.push(elements.clone());
            document.measured_elements(elements, trace.element_images.clone());
        }
        budget.spend(1)?;
        document.reformat(values, resolver)?;
    }
}

#[cfg(test)]
fn layout_with_work_limit(
    document: &StyledDocument,
    resolver: &dyn ResourceResolver,
    work_limit: usize,
) -> Result<LayoutTrace, LayoutError> {
    layout_pass(document, resolver, work::Budget::new(work_limit)).map(|pass| pass.trace)
}

fn layout_pass(
    document: &StyledDocument,
    resolver: &dyn ResourceResolver,
    budget: work::Budget,
) -> Result<LayoutPass, LayoutError> {
    let sheet = document.styles();
    let text = TextContext::new(&sheet.fonts, resolver);
    let page = document.page_box();
    let flow = crate::style::logical::Flow::used(document.root().style());
    let mut logical_geometry = page.geometry.clone();
    writing::Frame::physical(flow, page.geometry.paper)
        .inverse()
        .geometry(&mut logical_geometry);
    let canvas_rect = logical_geometry.content_box();
    let content_height = canvas_rect.height;
    let continuous = sheet.presentation() != crate::style::Presentation::Paged;
    let mut measurer = measure::Measurer::new(
        &text,
        document.root(),
        [canvas_rect.width, content_height],
        budget,
    );
    for block in document
        .running_strings()
        .iter()
        .filter_map(|assignment| assignment.element.as_ref())
        .flat_map(crate::document::RunningElement::blocks)
        .chain(document.footnotes())
    {
        measurer.sources.register(block);
    }
    measurer.canvas_images = document.canvas_background().backgrounds.has_images();
    measurer.element_targets = element_targets(document);
    measurer.unbroken = continuous;
    measurer.named_pages = !continuous;
    measurer.motion = std::rc::Rc::new(motion::Resources::new(
        document.svg_definitions(),
        &sheet.fonts,
    ));
    let root = (document.root().style().display != crate::style::Display::None)
        .then(|| {
            measurer.block(
                document.root(),
                canvas_rect.x,
                canvas_rect.width,
                document.root().style().used_rtl(),
                true,
                Some(content_height),
            )
        })
        .transpose()?;
    paginate(document, resolver, &mut measurer, root, canvas_rect)
}

/// Fragments the measured root into pages and paints them. Kept apart from `layout_pass`,
/// whose frame every nested navigable's layout stacks.
fn paginate<'t>(
    document: &'t StyledDocument,
    resolver: &'t dyn ResourceResolver,
    measurer: &mut measure::Measurer<'t>,
    root: Option<measure::MeasuredBlock<'t>>,
    canvas_rect: Rect,
) -> Result<LayoutPass, LayoutError> {
    let sheet = document.styles();
    let page = document.page_box();
    let [page_width, page_height] = page.geometry.paper;
    let flow = crate::style::logical::Flow::used(document.root().style());
    let continuous = sheet.presentation() != crate::style::Presentation::Paged;
    let page_output = PageRecord::new(page)?.output;
    let painting = page_paint::PagePaint::in_flow(page, document.canvas_background(), flow)?;
    let paginator = pagination::Paginator::for_document(
        measurer,
        physical_pages::PhysicalPages::new(document, resolver)?,
        painting.canvas.clone(),
        canvas_rect,
    );
    let pagination::Paginated {
        mut anchors,
        mut pages,
        mut display_lists,
        mut links,
        mut destinations,
        destination_bounds,
        page_boxes,
        mut page_records,
        string_locations,
        line_boxes: _,
        mut text_areas,
        mut renderings,
    } = if continuous {
        paginator.unbroken()
    } else {
        paginator
    }
    .document(
        root,
        document.navigation().destinations,
        document.root().leading_events(),
    )?;
    for (index, page) in page_boxes.iter().enumerate() {
        let frame = writing::Frame::physical(flow, page.geometry.paper);
        for area in &mut links[index] {
            match &mut area.shape {
                LinkShape::Rect(rect) => *rect = frame.rect(*rect),
                LinkShape::Quads(quads) => {
                    for point in quads.iter_mut().flatten() {
                        *point = frame.point(*point);
                    }
                }
            }
        }
        page_records[index] = PageRecord::new(page)?;
    }
    for (destination, bounds) in destinations.iter_mut().zip(destination_bounds) {
        if let (Some(destination), Some(bounds)) = (destination, bounds) {
            let frame = writing::Frame::physical(flow, page_boxes[destination.page].geometry.paper);
            destination.top = frame.rect(bounds).y;
        }
    }
    let generated = paged_content(
        document,
        &page_boxes,
        string_locations,
        &destinations,
        resolver,
        measurer,
        (&mut pages, &mut display_lists, &mut links, &mut text_areas),
    )?;
    for (((list, page), record), text_area) in display_lists
        .iter_mut()
        .zip(&page_boxes)
        .zip(&page_records)
        .zip(text_areas.iter_mut())
    {
        page_paint::PagePaint::new(page, document.canvas_background(), record.output.bleed)
            .decorate(list, text_area.take());
    }
    for (list, page) in display_lists.iter_mut().zip(&page_boxes) {
        list.extend(page_paint::page_outline(page));
    }
    for (areas, record) in links.iter_mut().zip(&page_records) {
        navigation::clip_links(areas, record.output.bleed);
    }
    anchors.physical(flow, &page_boxes);
    renderings.adopt(measurer.element_targets.displayed.take());
    let (elements, element_images) = element_renderings(
        document,
        &sheet.fonts,
        renderings,
        &measurer.element_targets.sampled.take(),
    )?;
    Ok(LayoutPass {
        generated,
        elements,
        container_sizes: std::mem::take(&mut measurer.container_sizes),
        anchor_frames: anchors.frames(sheet, &document.svg_definitions(), &measurer.work)?,
        trace: LayoutTrace {
            page_width,
            page_height,
            page_area: page.geometry.content_box(),
            page_output,
            page_records,
            pages,
            display_lists,
            links,
            destinations,
            fonts: sheet
                .fonts
                .faces()
                .iter()
                .map(|font| font.descriptor().clone())
                .collect(),
            element_images,
        },
    })
}

/// The elements whose renderings a layout of `document` records.
fn element_targets(document: &StyledDocument) -> std::rc::Rc<ElementTargets> {
    std::rc::Rc::new(ElementTargets {
        targets: document.element_images().targets(),
        root: Some(document.root_element()),
        displayed: std::cell::RefCell::default(),
        previous: document.element_renderings().clone(),
        shapes: document.element_images().shapes().clone(),
        sampled: std::cell::RefCell::default(),
    })
}

/// The states of the elements that `element()` images show, the renderings of those that
/// generate stacking contexts, drawn with the document's faces and SVG definitions, and the
/// alpha of these renderings where the layout's floats `sampled` the last layout's.
#[expect(
    clippy::boxed_local,
    reason = "layouts of nested navigables stack, so the layout frame holds the renderings boxed"
)]
fn element_renderings(
    document: &StyledDocument,
    fonts: &crate::fonts::FontBook,
    renderings: Box<pagination::Renderings>,
    sampled: &crate::document::ShapeSamples,
) -> Result<
    (
        Box<crate::document::ElementMeasurements>,
        Box<ElementRenderings>,
    ),
    LayoutError,
> {
    use crate::document::ElementState;
    let images = document.element_images();
    let states = images
        .targets()
        .into_iter()
        .map(|element| {
            let state = if let Some(rendering) = renderings.stacked.get(&element) {
                ElementState::Stacked(
                    rendering
                        .size
                        .map(|extent| extent / crate::style::POINTS_PER_PIXEL),
                )
            } else if renderings.unstacked.contains(&element) {
                ElementState::Unstacked
            } else {
                ElementState::NotRendered
            };
            (element, state)
        })
        .collect();
    let definitions = document.svg_definitions();
    let paints: ElementRenderings = renderings
        .stacked
        .into_iter()
        .map(|(element, rendering)| {
            let [width, height] = rendering.size;
            (
                element,
                std::sync::Arc::new(ViewportPaint {
                    items: rendering.items,
                    lines: Vec::new(),
                    fonts: fonts.clone(),
                    definitions: definitions.clone(),
                    area: Rect {
                        x: 0.0,
                        y: 0.0,
                        width,
                        height,
                    },
                    elements: Box::default(),
                }),
            )
        })
        .collect();
    // CSS Shapes 1 §6.1: a float's shape stands once the rendering it sampled stops changing;
    // an element no longer rendered changes its state instead.
    let shapes = sampled
        .keys()
        .filter(|(element, _)| paints.contains_key(element))
        .map(|&(element, samples)| {
            crate::writer::rendering_alpha(element, samples, &paints)
                .map(|alpha| ((element, samples), alpha.into()))
                .map_err(|error| LayoutError::Raster(Box::new(error)))
        })
        .collect::<Result<_, LayoutError>>()?;
    Ok((Box::new(images.measured(states, shapes)), Box::new(paints)))
}

/// Each page's text lines, display list, link areas and, when its page box's backgrounds clip
/// to text, text area.
pub(super) type PageOutputs<'p> = (
    &'p mut [Vec<TextLine>],
    &'p mut [Vec<DisplayItem>],
    &'p mut [Vec<LinkArea>],
    &'p mut [Option<crate::graphics::FlowPaint>],
);

/// Paints the page-margin boxes and resolves the generated content that depends on where
/// pagination placed the document. Kept apart from `layout_pass`, whose frame every nested
/// navigable's layout stacks.
fn paged_content<'t>(
    document: &'t StyledDocument,
    page_boxes: &[std::sync::Arc<crate::document::PageBox>],
    string_locations: strings::StringLocations,
    destinations: &[Option<Destination>],
    resolver: &dyn ResourceResolver,
    measurer: &mut measure::Measurer<'t>,
    (pages, display_lists, links, text_areas): PageOutputs<'_>,
) -> Result<Option<crate::document::GeneratedValues>, LayoutError> {
    let counters = page_counters::PageCounters::new(page_boxes);
    let strings = string_locations.resolve(document.running_strings(), &counters, pages.len())?;
    let first_margin_paragraph = measurer.sources.paragraph_count();
    page_margins::render(
        page_boxes,
        &page_margins::MarginContext {
            strings: &strings,
            running: document.running_strings(),
            destinations: document.navigation().destinations,
            counters: &counters,
            document,
            resolver,
        },
        measurer,
        first_margin_paragraph,
        (pages, display_lists, links, text_areas),
    )?;
    let destination_pages: Vec<_> = destinations
        .iter()
        .map(|destination| destination.as_ref().map(|destination| destination.page))
        .collect();
    Ok(document.resolve_generated(
        &destination_pages,
        crate::document::Paginated {
            pages: pages.len(),
            numbers: &|page| counters.page(page, None),
            context_page: &|context| strings.page_of(context),
            strings: &mut |context, request| strings.at_context(context, request),
            starts: counters.starts(page_boxes, strings.page_starts(pages.len())),
            running: page_margins::running(
                page_boxes,
                document.running_strings(),
                &strings,
                &counters,
            ),
        },
    )?)
}

#[derive(Debug, thiserror::Error)]
pub(crate) enum LayoutError {
    #[error("CSS anchor positioning did not stabilize")]
    AnchorPositioningCycle,
    #[error("generated content resolution repeats without reaching a fixed layout")]
    GeneratedContentCycle,
    #[error("container query sizes repeat without reaching a fixed layout")]
    ContainerQueryCycle,
    #[error("element() image renderings repeat without reaching a fixed layout")]
    ElementImageCycle,
    #[error("{0}")]
    Raster(Box<crate::writer::PdfError>),
    #[error("non-finite page production geometry")]
    NonFinitePageOutputGeometry,
    #[error("non-finite page-margin geometry at {location:?}")]
    NonFinitePageMarginGeometry {
        location: crate::style::MarginLocation,
    },
    #[error("{0}")]
    Style(#[from] crate::style::StyleError),
    #[error("{0}")]
    Document(#[from] crate::document::DocumentError),
    #[error("{0}")]
    Image(#[from] crate::images::ImageError),
    #[error("layout exceeds {limit} pages")]
    PageLimit { limit: usize },
    #[error("layout exceeds {limit} work units")]
    WorkLimit { limit: usize },
    #[error("non-finite geometry at block {block}")]
    NonFiniteBlockGeometry { block: usize },
    #[error("{0}")]
    Text(#[from] TextError),
    #[error("{0}")]
    Table(#[from] crate::table::TableError),
    #[error("{0}")]
    Flex(#[from] crate::flex::FlexError),
    #[error("unsupported flex formatting: {feature}")]
    UnsupportedFlex { feature: &'static str },
    #[error("unsupported footnote {footnote}: {feature}")]
    UnsupportedFootnote {
        footnote: usize,
        feature: &'static str,
    },
    #[error("invalid normalized table structure")]
    InvalidTableStructure,
    #[error("{0}")]
    Grid(#[from] crate::grid::GridError),
    #[error("invalid normalized grid structure")]
    InvalidGridStructure,
    #[error("overflow clip has no box fragment on page {page}")]
    MissingClipFragment { page: usize },
    #[error("containing block has no fragment on anchor page {page}")]
    MissingContainingFragment { page: usize },
    #[error("fixed boxes repeated on every page exceed {limit} placements")]
    FixedPlacementLimit { limit: usize },
}