mupdf 0.8.0

Safe Rust wrapper to MuPDF
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
use std::convert::TryFrom;
use std::ffi::{CStr, CString};
use std::fmt;
use std::io::{self, BufReader, Read, Write};
use std::slice;
use std::str::FromStr;

use mupdf_sys::*;

use crate::pdf::PdfAnnotation;
use crate::pdf::PdfDocument;
use crate::{context, Buffer, Error, Matrix};

pub trait IntoPdfDictKey {
    fn into_pdf_dict_key(self) -> Result<PdfObject, Error>;
}

impl IntoPdfDictKey for &str {
    fn into_pdf_dict_key(self) -> Result<PdfObject, Error> {
        PdfObject::new_name(self)
    }
}

impl IntoPdfDictKey for String {
    fn into_pdf_dict_key(self) -> Result<PdfObject, Error> {
        PdfObject::new_name(&self)
    }
}

impl IntoPdfDictKey for PdfObject {
    fn into_pdf_dict_key(self) -> Result<PdfObject, Error> {
        Ok(self)
    }
}

#[derive(Debug)]
pub struct PdfObject {
    pub(crate) inner: *mut pdf_obj,
}

impl PdfObject {
    pub(crate) unsafe fn from_raw(ptr: *mut pdf_obj) -> Self {
        Self { inner: ptr }
    }

    pub(crate) unsafe fn from_raw_keep_ref(ptr: *mut pdf_obj) -> Self {
        unsafe {
            pdf_keep_obj(context(), ptr);
            Self { inner: ptr }
        }
    }

    pub fn try_clone(&self) -> Result<Self, Error> {
        unsafe { ffi_try!(mupdf_pdf_clone_obj(context(), self.inner)) }.map(|inner| Self { inner })
    }

    pub fn new_null() -> PdfObject {
        unsafe {
            let inner = mupdf_pdf_new_null();
            PdfObject::from_raw(inner)
        }
    }

    pub fn new_bool(b: bool) -> PdfObject {
        unsafe {
            let inner = mupdf_pdf_new_bool(b);
            PdfObject::from_raw(inner)
        }
    }

    pub fn new_int(i: i32) -> Result<PdfObject, Error> {
        unsafe { ffi_try!(mupdf_pdf_new_int(context(), i)) }
            .map(|inner| unsafe { PdfObject::from_raw(inner) })
    }

    pub fn new_real(f: f32) -> Result<PdfObject, Error> {
        unsafe { ffi_try!(mupdf_pdf_new_real(context(), f)) }
            .map(|inner| unsafe { PdfObject::from_raw(inner) })
    }

    pub fn new_string(s: &str) -> Result<PdfObject, Error> {
        let c_str = CString::new(s)?;
        unsafe { ffi_try!(mupdf_pdf_new_string(context(), c_str.as_ptr())) }
            .map(|inner| unsafe { PdfObject::from_raw(inner) })
    }

    pub fn new_name(name: &str) -> Result<PdfObject, Error> {
        let c_name = CString::new(name)?;
        unsafe { ffi_try!(mupdf_pdf_new_name(context(), c_name.as_ptr())) }
            .map(|inner| unsafe { PdfObject::from_raw(inner) })
    }

    pub fn is_indirect(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_is_indirect(context(), self.inner)) }
    }

    pub fn is_null(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_is_null(context(), self.inner)) }
    }

    pub fn is_bool(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_is_bool(context(), self.inner)) }
    }

    pub fn is_int(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_is_int(context(), self.inner)) }
    }

    pub fn is_real(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_is_real(context(), self.inner)) }
    }

    pub fn is_number(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_is_number(context(), self.inner)) }
    }

    pub fn is_string(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_is_string(context(), self.inner)) }
    }

    pub fn is_name(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_is_name(context(), self.inner)) }
    }

    pub fn is_array(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_is_array(context(), self.inner)) }
    }

    pub fn is_dict(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_is_dict(context(), self.inner)) }
    }

    pub fn is_stream(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_is_stream(context(), self.inner)) }
    }

    pub fn as_bool(&self) -> Result<bool, Error> {
        unsafe { ffi_try!(mupdf_pdf_to_bool(context(), self.inner)) }
    }

    pub fn as_int(&self) -> Result<i32, Error> {
        unsafe { ffi_try!(mupdf_pdf_to_int(context(), self.inner)) }
    }

    pub fn as_float(&self) -> Result<f32, Error> {
        unsafe { ffi_try!(mupdf_pdf_to_float(context(), self.inner)) }
    }

    pub fn as_indirect(&self) -> Result<i32, Error> {
        unsafe { ffi_try!(mupdf_pdf_to_indirect(context(), self.inner)) }
    }

    pub fn as_name(&self) -> Result<Vec<u8>, Error> {
        let name_ptr = unsafe { ffi_try!(mupdf_pdf_to_name(context(), self.inner)) }?;
        if name_ptr.is_null() {
            return Err(Error::UnexpectedNullPtr);
        }
        Ok(unsafe { CStr::from_ptr(name_ptr) }.to_bytes().to_vec())
    }

    pub fn as_string(&self) -> Result<String, Error> {
        let str_ptr = unsafe { ffi_try!(mupdf_pdf_to_string(context(), self.inner)) }?;
        if str_ptr.is_null() {
            return Err(Error::UnexpectedNullPtr);
        }
        let c_str = unsafe { CStr::from_ptr(str_ptr) };
        c_str
            .to_str()
            .map(ToOwned::to_owned)
            .map_err(|_| Error::InvalidUtf8)
    }

    pub fn as_bytes(&self) -> Result<Vec<u8>, Error> {
        let mut len = 0;
        let ptr = unsafe { ffi_try!(mupdf_pdf_to_bytes(context(), self.inner, &mut len)) }?;
        if ptr.is_null() {
            return Err(Error::UnexpectedNullPtr);
        }
        Ok(unsafe { slice::from_raw_parts(ptr, len) }.to_vec())
    }

    pub fn resolve(&self) -> Result<Option<Self>, Error> {
        let inner = unsafe { ffi_try!(mupdf_pdf_resolve_indirect(context(), self.inner)) }?;
        if inner.is_null() {
            return Ok(None);
        }
        Ok(Some(Self { inner }))
    }

    pub fn read_stream(&self) -> Result<Vec<u8>, Error> {
        let inner = unsafe { ffi_try!(mupdf_pdf_read_stream(context(), self.inner)) }?;
        let buf = unsafe { Buffer::from_raw(inner) };
        let buf_len = buf.len();
        let mut reader = BufReader::new(buf);
        let mut output = Vec::with_capacity(buf_len);
        reader.read_to_end(&mut output)?;
        Ok(output)
    }

    pub fn read_raw_stream(&self) -> Result<Vec<u8>, Error> {
        let inner = unsafe { ffi_try!(mupdf_pdf_read_raw_stream(context(), self.inner)) }?;
        let buf = unsafe { Buffer::from_raw(inner) };
        let buf_len = buf.len();
        let mut reader = BufReader::new(buf);
        let mut output = Vec::with_capacity(buf_len);
        reader.read_to_end(&mut output)?;
        Ok(output)
    }

    pub fn write_object(&mut self, obj: &PdfObject) -> Result<(), Error> {
        unsafe { ffi_try!(mupdf_pdf_write_object(context(), self.inner, obj.inner)) }
    }

    pub fn write_stream_buffer(&mut self, buf: &Buffer) -> Result<(), Error> {
        unsafe {
            ffi_try!(mupdf_pdf_write_stream_buffer(
                context(),
                self.inner,
                buf.inner,
                0
            ))
        }
    }

    pub fn write_stream_string(&mut self, string: &str) -> Result<(), Error> {
        let buf = Buffer::from_str(string)?;
        self.write_stream_buffer(&buf)
    }

    pub fn write_raw_stream_buffer(&mut self, buf: &Buffer) -> Result<(), Error> {
        unsafe {
            ffi_try!(mupdf_pdf_write_stream_buffer(
                context(),
                self.inner,
                buf.inner,
                1
            ))
        }
    }

    pub fn write_raw_stream_string(&mut self, string: &str) -> Result<(), Error> {
        let buf = Buffer::from_str(string)?;
        self.write_raw_stream_buffer(&buf)
    }

    pub fn get_array(&self, index: i32) -> Result<Option<Self>, Error> {
        let inner = unsafe { ffi_try!(mupdf_pdf_array_get(context(), self.inner, index)) }?;
        if inner.is_null() {
            return Ok(None);
        }
        Ok(Some(Self { inner }))
    }

    pub fn dict_len(&self) -> Result<usize, Error> {
        unsafe { ffi_try!(mupdf_pdf_dict_len(context(), self.inner)) }.map(|size| size as usize)
    }

    pub fn get_dict_val(&self, idx: i32) -> Result<Option<Self>, Error> {
        let inner = unsafe { ffi_try!(mupdf_pdf_dict_get_val(context(), self.inner, idx)) }?;
        if inner.is_null() {
            return Ok(None);
        }
        Ok(Some(Self { inner }))
    }
    pub fn get_dict_key(&self, idx: i32) -> Result<Option<Self>, Error> {
        let inner = unsafe { ffi_try!(mupdf_pdf_dict_get_key(context(), self.inner, idx)) }?;
        if inner.is_null() {
            return Ok(None);
        }
        Ok(Some(Self { inner }))
    }

    pub fn get_dict<K: IntoPdfDictKey>(&self, key: K) -> Result<Option<Self>, Error> {
        let key = key.into_pdf_dict_key()?;
        let inner = unsafe { ffi_try!(mupdf_pdf_dict_get(context(), self.inner, key.inner)) }?;
        if inner.is_null() {
            return Ok(None);
        }
        Ok(Some(Self { inner }))
    }

    pub fn get_dict_inheritable<K: IntoPdfDictKey>(&self, key: K) -> Result<Option<Self>, Error> {
        let key = key.into_pdf_dict_key()?;
        let inner = unsafe {
            ffi_try!(mupdf_pdf_dict_get_inheritable(
                context(),
                self.inner,
                key.inner
            ))
        }?;
        if inner.is_null() {
            return Ok(None);
        }
        Ok(Some(Self { inner }))
    }

    #[allow(clippy::len_without_is_empty)]
    pub fn len(&self) -> Result<usize, Error> {
        unsafe { ffi_try!(mupdf_pdf_array_len(context(), self.inner)) }.map(|size| size as usize)
    }

    /// Creates a shallow copy of this array, resolving any indirect reference.
    ///
    /// Wraps `pdf_copy_array`: resolves `self` if indirect, then copies each
    /// element into a new direct array. Returns an error if `self` is not an
    /// array.
    pub fn copy_array(&self) -> Result<Self, Error> {
        unsafe { ffi_try!(mupdf_pdf_copy_array(context(), self.inner)) }
            .map(|inner| unsafe { Self::from_raw(inner) })
    }

    /// Creates a shallow copy of this dictionary, resolving any indirect reference.
    ///
    /// Wraps `pdf_copy_dict`: resolves `self` if indirect, then copies each
    /// entry into a new direct dictionary. Returns an error if `self` is not a
    /// dictionary.
    pub fn copy_dict(&self) -> Result<Self, Error> {
        unsafe { ffi_try!(mupdf_pdf_copy_dict(context(), self.inner)) }
            .map(|inner| unsafe { Self::from_raw(inner) })
    }

    pub fn array_put(&mut self, index: i32, value: Self) -> Result<(), Error> {
        unsafe {
            ffi_try!(mupdf_pdf_array_put(
                context(),
                self.inner,
                index,
                value.inner
            ))
        }
    }

    pub fn array_push(&mut self, value: Self) -> Result<(), Error> {
        unsafe { ffi_try!(mupdf_pdf_array_push(context(), self.inner, value.inner)) }
    }

    pub(crate) fn array_push_ref(&mut self, value: &Self) -> Result<(), Error> {
        // From MUPDF (https://ghostscript.com/~robin/mupdf_explored.pdf, p. 238)
        // The array will take new references to the object passed in - that is, after the call,
        // both the array and the caller will hold references to the object. In cases where the
        // object to be inserted is a ‘borrowed’ reference, this is ideal.
        unsafe { ffi_try!(mupdf_pdf_array_push(context(), self.inner, value.inner)) }
    }

    pub fn array_delete(&mut self, index: i32) -> Result<(), Error> {
        unsafe { ffi_try!(mupdf_pdf_array_delete(context(), self.inner, index)) }
    }

    pub fn dict_put<K: IntoPdfDictKey>(&mut self, key: K, value: Self) -> Result<(), Error> {
        self.dict_put_ref(key, &value)
    }

    pub(crate) fn dict_put_ref<K: IntoPdfDictKey>(
        &mut self,
        key: K,
        value: &Self,
    ) -> Result<(), Error> {
        // The same as array_push_ref, look at
        // https://github.com/ArtifexSoftware/mupdf/blob/60bf95d09f496ab67a5e4ea872bdd37a74b745fe/source/pdf/pdf-object.c#L2505
        let key_obj = key.into_pdf_dict_key()?;
        unsafe {
            ffi_try!(mupdf_pdf_dict_put(
                context(),
                self.inner,
                key_obj.inner,
                value.inner
            ))
        }
    }

    pub fn dict_delete<K: IntoPdfDictKey>(&mut self, key: K) -> Result<(), Error> {
        let key_obj = key.into_pdf_dict_key()?;
        unsafe { ffi_try!(mupdf_pdf_dict_delete(context(), self.inner, key_obj.inner)) }
    }

    /// Returns an iterator over the elements of this array.
    ///
    /// Each yielded [`PdfObject`] is independently reference-counted, so it stays
    /// valid even after the source object is dropped. The items are `Result`s so
    /// errors surface per-element rather than aborting the whole iteration.
    ///
    /// This is the ergonomic replacement for looping with
    /// [`get_array`](Self::get_array):
    ///
    /// ```text
    /// for item in arr.array_iter()? {
    ///     let item = item?;
    ///     // ...
    /// }
    /// ```
    ///
    /// Returns an error if `self` is not an array.
    pub fn array_iter(&self) -> Result<PdfArrayIter<'_>, Error> {
        if !self.is_array()? {
            return Err(Error::InvalidArgument(
                "PdfObject is not an array".to_string(),
            ));
        }
        Ok(PdfArrayIter {
            obj: self,
            index: 0,
            len: i32::try_from(self.len()?)?,
        })
    }

    /// Returns an iterator over the `(key, value)` pairs of this dictionary.
    ///
    /// Both halves of each pair are independently reference-counted [`PdfObject`]s
    /// that stay valid after the source object is dropped. Keys are PDF name
    /// objects; read them with [`as_name`](Self::as_name).
    ///
    /// This is the ergonomic replacement for looping with
    /// [`get_dict_key`](Self::get_dict_key) and [`get_dict_val`](Self::get_dict_val).
    /// Returns an error if `self` is not a dictionary.
    pub fn dict_iter(&self) -> Result<PdfDictIter<'_>, Error> {
        if !self.is_dict()? {
            return Err(Error::InvalidArgument(
                "PdfObject is not a dictionary".to_string(),
            ));
        }
        Ok(PdfDictIter {
            obj: self,
            index: 0,
            len: i32::try_from(self.dict_len()?)?,
        })
    }

    fn print(&self, tight: bool, ascii: bool) -> Result<String, Error> {
        let ptr =
            unsafe { ffi_try!(mupdf_pdf_obj_to_string(context(), self.inner, tight, ascii)) }?;
        let c_str = unsafe { CStr::from_ptr(ptr) };
        let s = c_str.to_string_lossy().into_owned();
        unsafe { fz_free(context(), ptr.cast()) };
        Ok(s)
    }

    pub fn document(&self) -> Option<PdfDocument> {
        unsafe {
            let ptr = mupdf_pdf_get_bound_document(context(), self.inner);
            if ptr.is_null() {
                return None;
            }
            Some(PdfDocument::from_raw(ptr))
        }
    }

    pub fn page_ctm(&self) -> Result<Matrix, Error> {
        unsafe { ffi_try!(mupdf_pdf_page_obj_transform(context(), self.inner)) }.map(Into::into)
    }
}

/// Iterator over the elements of a PDF array.
///
/// Created by [`PdfObject::array_iter`]. Each item is a `Result<PdfObject, Error>`;
/// unwrap it with `?` inside the loop body.
#[derive(Debug)]
pub struct PdfArrayIter<'a> {
    obj: &'a PdfObject,
    index: i32,
    len: i32,
}

impl Iterator for PdfArrayIter<'_> {
    type Item = Result<PdfObject, Error>;

    fn next(&mut self) -> Option<Self::Item> {
        if self.index >= self.len {
            return None;
        }
        let idx = self.index;
        self.index += 1;
        match self.obj.get_array(idx) {
            Ok(Some(obj)) => Some(Ok(obj)),
            // Within bounds an element always exists. A null return means the
            // underlying object changed (e.g. mutated through another handle)
            // since we measured its length; surface that as an error rather than
            // silently truncating iteration and breaking ExactSizeIterator.
            Ok(None) => Some(Err(Error::UnexpectedNullPtr)),
            Err(err) => Some(Err(err)),
        }
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        let remaining = (self.len - self.index) as usize;
        (remaining, Some(remaining))
    }
}

impl ExactSizeIterator for PdfArrayIter<'_> {
    fn len(&self) -> usize {
        (self.len - self.index) as usize
    }
}

/// Iterator over the `(key, value)` pairs of a PDF dictionary.
///
/// Created by [`PdfObject::dict_iter`].
#[derive(Debug)]
pub struct PdfDictIter<'a> {
    obj: &'a PdfObject,
    index: i32,
    len: i32,
}

impl Iterator for PdfDictIter<'_> {
    type Item = Result<(PdfObject, PdfObject), Error>;

    fn next(&mut self) -> Option<Self::Item> {
        if self.index >= self.len {
            return None;
        }
        let idx = self.index;
        self.index += 1;
        let key = match self.obj.get_dict_key(idx) {
            Ok(Some(key)) => key,
            // A null return within bounds means the dict changed under us; treat
            // it as an error instead of silently ending iteration.
            Ok(None) => return Some(Err(Error::UnexpectedNullPtr)),
            Err(err) => return Some(Err(err)),
        };
        let val = match self.obj.get_dict_val(idx) {
            Ok(Some(val)) => val,
            Ok(None) => return Some(Err(Error::UnexpectedNullPtr)),
            Err(err) => return Some(Err(err)),
        };
        Some(Ok((key, val)))
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        let remaining = (self.len - self.index) as usize;
        (remaining, Some(remaining))
    }
}

impl ExactSizeIterator for PdfDictIter<'_> {
    fn len(&self) -> usize {
        (self.len - self.index) as usize
    }
}

impl Write for PdfObject {
    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
        let len = buf.len();
        let mut fz_buf = Buffer::with_capacity(len);
        fz_buf.write(buf)?;
        self.write_stream_buffer(&fz_buf)
            .map_err(io::Error::other)?;
        Ok(len)
    }

    fn flush(&mut self) -> io::Result<()> {
        Ok(())
    }
}

impl Drop for PdfObject {
    fn drop(&mut self) {
        if !self.inner.is_null() {
            unsafe {
                pdf_drop_obj(context(), self.inner);
            }
        }
    }
}

impl Clone for PdfObject {
    fn clone(&self) -> PdfObject {
        self.try_clone().unwrap()
    }
}

impl fmt::Display for PdfObject {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let s = self.print(true, false).unwrap();
        f.write_str(&s)
    }
}

impl From<bool> for PdfObject {
    fn from(b: bool) -> PdfObject {
        PdfObject::new_bool(b)
    }
}

impl TryFrom<i32> for PdfObject {
    type Error = Error;

    fn try_from(i: i32) -> Result<PdfObject, Self::Error> {
        PdfObject::new_int(i)
    }
}

impl TryFrom<f32> for PdfObject {
    type Error = Error;

    fn try_from(f: f32) -> Result<PdfObject, Self::Error> {
        PdfObject::new_real(f)
    }
}

impl TryFrom<&str> for PdfObject {
    type Error = Error;

    fn try_from(s: &str) -> Result<PdfObject, Self::Error> {
        PdfObject::new_string(s)
    }
}

impl TryFrom<String> for PdfObject {
    type Error = Error;

    fn try_from(s: String) -> Result<PdfObject, Self::Error> {
        PdfObject::new_string(&s)
    }
}

impl TryFrom<&PdfAnnotation> for PdfObject {
    type Error = Error;

    fn try_from(annot: &PdfAnnotation) -> Result<PdfObject, Self::Error> {
        unsafe { ffi_try!(mupdf_pdf_annot_obj(context(), annot.inner.as_ptr())) }
            .map(|inner| unsafe { PdfObject::from_raw_keep_ref(inner) })
    }
}