alpha2-host-core 0.8.0

FFmpeg-free native host logic for alpha2: the policies, audio timelines, cursor rules, providers, plugin runtime, protocol frames and request parsing native hosts share, and the decode, export and still pipeline the mobile hosts run.
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
//! Still picture decoding (PNG, JPEG, WebP) to straight RGBA, with the Exif orientation.
//!
//! Embedded ICC profiles are ignored: samples are read as sRGB code values, as the desktop host
//! reads them.

use std::io::Cursor;

use alpha2_media::{
    CancelToken, ChromaLocation, DecodeError, DecodeEvent, DecodeRequest, DecodeResult,
    DecodedVideoFrame, Decoder, Orientation, PixelFormat, Plane, Rect, SampleAspectRatio,
    StreamInfo, StreamKind, frame_size_supported,
};
use alpha2_time::MediaTime;

/// A still picture container, told apart by its signature.
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum StillFormat {
    /// PNG; an animated PNG reads as its default image.
    Png,
    /// JPEG (JFIF or Exif), baseline or progressive.
    Jpeg,
    /// WebP, lossy or lossless, with or without alpha; an animated WebP is refused.
    WebP,
}

impl StillFormat {
    /// A stable name for messages.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Png => "PNG",
            Self::Jpeg => "JPEG",
            Self::WebP => "WebP",
        }
    }
}

/// The format whose signature starts `head`, which needs its first 12 bytes for WebP.
#[must_use]
pub fn still_format(head: &[u8]) -> Option<StillFormat> {
    if head.starts_with(&[0xff, 0xd8, 0xff]) {
        Some(StillFormat::Jpeg)
    } else if head.starts_with(b"\x89PNG\r\n\x1a\n") {
        Some(StillFormat::Png)
    } else if head.len() >= 12 && head.starts_with(b"RIFF") && &head[8..12] == b"WEBP" {
        Some(StillFormat::WebP)
    } else {
        None
    }
}

/// What a still's headers say, read without decoding its samples.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct StillInfo {
    /// The container.
    pub format: StillFormat,
    /// Stored width in pixels, before orientation.
    pub width: u32,
    /// Stored height in pixels, before orientation.
    pub height: u32,
    /// How the picture is shown upright, from its Exif `Orientation`.
    pub orientation: Orientation,
}

/// A decoded still picture.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DecodedStill {
    /// What the headers say.
    pub info: StillInfo,
    /// Straight (not premultiplied) 8-bit RGBA rows, `width * 4` bytes each, as stored.
    pub rgba: Vec<u8>,
}

impl DecodedStill {
    /// The picture as one straight RGBA frame at time zero. It carries no color tags; the
    /// renderer reads RGBA samples as sRGB code values.
    #[must_use]
    pub fn into_video_frame(self) -> DecodedVideoFrame {
        let StillInfo {
            width,
            height,
            orientation,
            ..
        } = self.info;
        DecodedVideoFrame {
            pts: MediaTime::ZERO,
            dts: None,
            duration: None,
            visible_rect: Rect {
                x: 0,
                y: 0,
                width,
                height,
            },
            sample_aspect_ratio: SampleAspectRatio::default(),
            orientation,
            pixel_format: PixelFormat::Rgba8,
            chroma_location: ChromaLocation::Unspecified,
            color: None,
            planes: vec![Plane {
                bytes: self.rgba.into(),
                stride: width * 4,
                width,
                height,
            }],
        }
    }
}

/// Reads a still's format, stored size and orientation from its headers.
///
/// # Errors
/// [`DecodeError::Unsupported`] for bytes that are no PNG, JPEG or WebP and for pictures past
/// the engine's frame limits; [`DecodeError::Adapter`] for malformed headers.
pub fn probe_still(bytes: &[u8]) -> Result<StillInfo, DecodeError> {
    let format = still_format(bytes).ok_or_else(not_a_still)?;
    let (width, height) = contained(format, || match format {
        StillFormat::Png => Ok(png_decoder(bytes)
            .read_header_info()
            .map_err(|error| png_error(&error))?
            .size()),
        StillFormat::Jpeg => {
            let mut decoder = jpeg_decoder(bytes);
            decoder.decode_headers().map_err(jpeg_error)?;
            jpeg_size(&decoder)
        }
        StillFormat::WebP => Ok(webp_decoder(bytes)?.dimensions()),
    })?;
    check_size(format, width, height)?;
    Ok(StillInfo {
        format,
        width,
        height,
        orientation: orientation(format, bytes),
    })
}

/// Decodes a PNG, JPEG or WebP still to straight RGBA.
///
/// Palette, grayscale, 16-bit and interlaced PNGs, progressive, grayscale and CMYK JPEGs, and
/// lossy or lossless WebP with alpha all expand to RGBA. An animated PNG decodes its default
/// image. Sizes are checked against the engine's frame limits before allocating.
///
/// # Errors
/// As [`probe_still`], [`DecodeError::Unsupported`] for an animated WebP, and
/// [`DecodeError::Adapter`] for undecodable samples, including those a decoder panics on.
pub fn decode_still(bytes: &[u8]) -> Result<DecodedStill, DecodeError> {
    let format = still_format(bytes).ok_or_else(not_a_still)?;
    let (width, height, rgba) = contained(format, || match format {
        StillFormat::Png => decode_png(bytes),
        StillFormat::Jpeg => decode_jpeg(bytes),
        StillFormat::WebP => decode_webp(bytes),
    })?;
    Ok(DecodedStill {
        info: StillInfo {
            format,
            width,
            height,
            orientation: orientation(format, bytes),
        },
        rgba,
    })
}

/// Runs a decoder, turning its panic into [`DecodeError::Adapter`]. The decoder crates panic on
/// some malformed input where arithmetic overflow checks are on, as in alpha2's release builds.
fn contained<T>(
    format: StillFormat,
    decode: impl FnOnce() -> Result<T, DecodeError>,
) -> Result<T, DecodeError> {
    std::panic::catch_unwind(std::panic::AssertUnwindSafe(decode)).unwrap_or_else(|payload| {
        Err(DecodeError::Adapter(format!(
            "{}: the decoder panicked: {}",
            format.as_str(),
            crate::panic_text(&*payload)
        )))
    })
}

fn not_a_still() -> DecodeError {
    DecodeError::Unsupported("not a PNG, JPEG or WebP picture".into())
}

fn check_size(format: StillFormat, width: u32, height: u32) -> Result<(), DecodeError> {
    if width == 0 || height == 0 {
        return Err(DecodeError::Adapter(format!(
            "{}: a {width}x{height} picture is empty",
            format.as_str()
        )));
    }
    if frame_size_supported(width, height) {
        Ok(())
    } else {
        Err(DecodeError::Unsupported(format!(
            "{}: a {width}x{height} picture is larger than {} pixels or {} on a side",
            format.as_str(),
            alpha2_media::MAX_FRAME_PIXELS,
            alpha2_media::MAX_FRAME_DIMENSION
        )))
    }
}

/// A zeroed RGBA buffer for a size [`check_size`] accepted.
fn rgba_buffer(width: u32, height: u32) -> Vec<u8> {
    // Within the frame limits, so at most 2^28 bytes.
    vec![0; width as usize * height as usize * 4]
}

/// Rewrites `pixels` packed pixels of `source_size` bytes at the front of `buffer` as RGBA.
///
/// Walks forward when pixels shrink and backward when they grow, so no pixel is overwritten
/// before it is read.
fn expand_in_place(
    buffer: &mut [u8],
    pixels: usize,
    source_size: usize,
    to_rgba: impl Fn(&[u8]) -> [u8; 4],
) {
    let mut convert = |index: usize| {
        let mut source = [0; 8];
        let start = index * source_size;
        source[..source_size].copy_from_slice(&buffer[start..start + source_size]);
        buffer[index * 4..index * 4 + 4].copy_from_slice(&to_rgba(&source[..source_size]));
    };
    if source_size >= 4 {
        (0..pixels).for_each(&mut convert);
    } else {
        (0..pixels).rev().for_each(&mut convert);
    }
}

fn png_decoder(bytes: &[u8]) -> png::Decoder<Cursor<&[u8]>> {
    let mut decoder = png::Decoder::new(Cursor::new(bytes));
    decoder.set_ignore_text_chunk(true);
    decoder.set_ignore_iccp_chunk(true);
    decoder
}

fn png_error(error: &png::DecodingError) -> DecodeError {
    DecodeError::Adapter(format!("PNG: {error}"))
}

fn decode_png(bytes: &[u8]) -> Result<(u32, u32, Vec<u8>), DecodeError> {
    let mut decoder = png_decoder(bytes);
    let (width, height) = decoder
        .read_header_info()
        .map_err(|error| png_error(&error))?
        .size();
    check_size(StillFormat::Png, width, height)?;
    decoder.set_transformations(png::Transformations::EXPAND);
    let mut reader = decoder.read_info().map_err(|error| png_error(&error))?;
    let (color, depth) = reader.output_color_type();
    let channels = color.samples();
    let sample_size = if depth == png::BitDepth::Sixteen {
        2
    } else {
        1
    };
    let pixels = width as usize * height as usize;
    let source_size = channels * sample_size;
    let mut buffer = vec![0; pixels * source_size.max(4)];
    let written = reader
        .output_buffer_size()
        .and_then(|written| buffer.get_mut(..written))
        .ok_or_else(|| DecodeError::Adapter("PNG: the decoded size disagrees".into()))?;
    let frame = reader
        .next_frame(written)
        .map_err(|error| png_error(&error))?;
    // The first frame is the `IDAT` image; an `fcTL` before it must give the canvas size.
    if (frame.width, frame.height) != (width, height) {
        return Err(DecodeError::Adapter(format!(
            "PNG: a {}x{} picture in a {width}x{height} canvas",
            frame.width, frame.height
        )));
    }
    let wide = |sample: &[u8]| round_16_to_8(u16::from_be_bytes([sample[0], sample[1]]));
    match (channels, sample_size) {
        (4, 1) => {}
        (3, 1) => expand_in_place(&mut buffer, pixels, 3, |p| [p[0], p[1], p[2], 255]),
        (2, 1) => expand_in_place(&mut buffer, pixels, 2, |p| [p[0], p[0], p[0], p[1]]),
        (1, 1) => expand_in_place(&mut buffer, pixels, 1, |p| [p[0], p[0], p[0], 255]),
        (4, 2) => expand_in_place(&mut buffer, pixels, 8, |p| {
            [wide(&p[0..]), wide(&p[2..]), wide(&p[4..]), wide(&p[6..])]
        }),
        (3, 2) => expand_in_place(&mut buffer, pixels, 6, |p| {
            [wide(&p[0..]), wide(&p[2..]), wide(&p[4..]), 255]
        }),
        (2, 2) => expand_in_place(&mut buffer, pixels, 4, |p| {
            let gray = wide(p);
            [gray, gray, gray, wide(&p[2..])]
        }),
        (1, 2) => expand_in_place(&mut buffer, pixels, 2, |p| {
            let gray = wide(p);
            [gray, gray, gray, 255]
        }),
        _ => {
            return Err(DecodeError::Unsupported(format!(
                "PNG: {color:?} at {} bits after expansion",
                depth as u8
            )));
        }
    }
    buffer.truncate(pixels * 4);
    if source_size > 4 {
        buffer.shrink_to_fit();
    }
    Ok((width, height, buffer))
}

/// A 16-bit sample on the 8-bit scale: `value / 256` rounded half up, at most 255.
fn round_16_to_8(value: u16) -> u8 {
    u8::try_from((u32::from(value) + 128) >> 8).unwrap_or(u8::MAX)
}

fn jpeg_decoder(bytes: &[u8]) -> zune_jpeg::JpegDecoder<zune_core::bytestream::ZCursor<&[u8]>> {
    // Any 16-bit side parses, so `check_size` gives the refusal.
    let options = zune_core::options::DecoderOptions::default()
        .set_max_width(usize::from(u16::MAX))
        .set_max_height(usize::from(u16::MAX))
        // RGB, not RGBA: zune-jpeg 0.5 misaligns four-channel output from CMYK and YCCK.
        .jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::RGB);
    zune_jpeg::JpegDecoder::new_with_options(zune_core::bytestream::ZCursor::new(bytes), options)
}

fn jpeg_error(error: zune_jpeg::errors::DecodeErrors) -> DecodeError {
    match error {
        zune_jpeg::errors::DecodeErrors::Unsupported(scheme) => {
            DecodeError::Unsupported(format!("JPEG: {scheme:?}"))
        }
        error => DecodeError::Adapter(format!("JPEG: {error}")),
    }
}

fn jpeg_size<T: zune_core::bytestream::ZByteReaderTrait>(
    decoder: &zune_jpeg::JpegDecoder<T>,
) -> Result<(u32, u32), DecodeError> {
    let malformed = || DecodeError::Adapter("JPEG: no frame header".into());
    let (width, height) = decoder.dimensions().ok_or_else(malformed)?;
    let side = |value: usize| u32::try_from(value).map_err(|_| malformed());
    Ok((side(width)?, side(height)?))
}

fn decode_jpeg(bytes: &[u8]) -> Result<(u32, u32, Vec<u8>), DecodeError> {
    let mut decoder = jpeg_decoder(bytes);
    decoder.decode_headers().map_err(jpeg_error)?;
    let (width, height) = jpeg_size(&decoder)?;
    check_size(StillFormat::Jpeg, width, height)?;
    let mut rgba = rgba_buffer(width, height);
    let pixels = width as usize * height as usize;
    decoder
        .decode_into(&mut rgba[..pixels * 3])
        .map_err(jpeg_error)?;
    expand_in_place(&mut rgba, pixels, 3, |p| [p[0], p[1], p[2], 255]);
    Ok((width, height, rgba))
}

fn webp_error(error: image_webp::DecodingError) -> DecodeError {
    match error {
        image_webp::DecodingError::UnsupportedFeature(feature) => {
            DecodeError::Unsupported(format!("WebP: {feature}"))
        }
        error => DecodeError::Adapter(format!("WebP: {error}")),
    }
}

/// A WebP decoder past the headers of a picture that is not animated.
fn webp_decoder(bytes: &[u8]) -> Result<image_webp::WebPDecoder<Cursor<&[u8]>>, DecodeError> {
    let decoder = image_webp::WebPDecoder::new(Cursor::new(bytes)).map_err(webp_error)?;
    if decoder.is_animated() {
        return Err(DecodeError::Unsupported(
            "WebP: an animated picture is not a still".into(),
        ));
    }
    Ok(decoder)
}

fn decode_webp(bytes: &[u8]) -> Result<(u32, u32, Vec<u8>), DecodeError> {
    let mut decoder = webp_decoder(bytes)?;
    let (width, height) = decoder.dimensions();
    check_size(StillFormat::WebP, width, height)?;
    let mut rgba = rgba_buffer(width, height);
    let pixels = width as usize * height as usize;
    if decoder.has_alpha() {
        decoder.read_image(&mut rgba).map_err(webp_error)?;
    } else {
        decoder
            .read_image(&mut rgba[..pixels * 3])
            .map_err(webp_error)?;
        expand_in_place(&mut rgba, pixels, 3, |p| [p[0], p[1], p[2], 255]);
    }
    Ok((width, height, rgba))
}

/// The orientation the still's Exif `Orientation` tag names, upright when there is none.
fn orientation(format: StillFormat, bytes: &[u8]) -> Orientation {
    let exif = match format {
        StillFormat::Jpeg => jpeg_exif(bytes),
        StillFormat::Png => png_exif(bytes),
        StillFormat::WebP => webp_exif(bytes),
    };
    exif.and_then(exif_orientation)
        .and_then(Orientation::from_exif)
        .unwrap_or(Orientation::UPRIGHT)
}

/// The TIFF structure of the first `APP1` Exif segment before the first scan.
fn jpeg_exif(bytes: &[u8]) -> Option<&[u8]> {
    let mut at = 2;
    loop {
        // Markers may be padded with any number of 0xFF fill bytes.
        while *bytes.get(at)? == 0xff && bytes.get(at + 1) == Some(&0xff) {
            at += 1;
        }
        if *bytes.get(at)? != 0xff {
            return None;
        }
        let marker = *bytes.get(at + 1)?;
        at += 2;
        match marker {
            // Start of scan, end of image.
            0xda | 0xd9 => return None,
            // Markers without a length: TEM and RSTn.
            0x01 | 0xd0..=0xd7 => continue,
            _ => {}
        }
        let length = usize::from(u16::from_be_bytes([*bytes.get(at)?, *bytes.get(at + 1)?]));
        let segment = bytes.get(at + 2..at.checked_add(length)?)?;
        if marker == 0xe1
            && let Some(tiff) = segment.strip_prefix(b"Exif\0\0")
        {
            return Some(tiff);
        }
        at += length;
    }
}

/// The payload of the first `eXIf` chunk.
fn png_exif(bytes: &[u8]) -> Option<&[u8]> {
    let mut at = 8;
    loop {
        let length =
            usize::try_from(u32::from_be_bytes(bytes.get(at..at + 4)?.try_into().ok()?)).ok()?;
        let kind = bytes.get(at + 4..at + 8)?;
        let data = bytes.get(at + 8..(at + 8).checked_add(length)?)?;
        match kind {
            b"eXIf" => return Some(data),
            b"IEND" => return None,
            _ => at += 12 + length,
        }
    }
}

/// The payload of the first `EXIF` chunk.
fn webp_exif(bytes: &[u8]) -> Option<&[u8]> {
    let mut at = 12;
    loop {
        let kind = bytes.get(at..at + 4)?;
        let length = usize::try_from(u32::from_le_bytes(
            bytes.get(at + 4..at + 8)?.try_into().ok()?,
        ))
        .ok()?;
        let data = bytes.get(at + 8..(at + 8).checked_add(length)?)?;
        if kind == b"EXIF" {
            return Some(data);
        }
        // Chunks are padded to an even size.
        at += 8 + length + (length & 1);
    }
}

/// The `Orientation` (0x0112) value in IFD0 of an Exif TIFF structure.
///
/// PNG `eXIf` and WebP `EXIF` chunks hold the TIFF structure itself; one that starts with the
/// JPEG `Exif\0\0` prefix is malformed and names no orientation.
fn exif_orientation(tiff: &[u8]) -> Option<u16> {
    let big_endian = match tiff.get(..4)? {
        b"II*\0" => false,
        b"MM\0*" => true,
        _ => return None,
    };
    let u16_at = |at: usize| {
        let bytes = tiff.get(at..at.checked_add(2)?)?.try_into().ok()?;
        Some(if big_endian {
            u16::from_be_bytes(bytes)
        } else {
            u16::from_le_bytes(bytes)
        })
    };
    let u32_at = |at: usize| {
        let bytes = tiff.get(at..at.checked_add(4)?)?.try_into().ok()?;
        Some(if big_endian {
            u32::from_be_bytes(bytes)
        } else {
            u32::from_le_bytes(bytes)
        })
    };
    let ifd = usize::try_from(u32_at(4)?).ok()?;
    let entries = usize::from(u16_at(ifd)?);
    (0..entries).find_map(|index| {
        let entry = ifd.checked_add(2 + index * 12)?;
        if u16_at(entry)? != 0x0112 || u32_at(entry + 4)? != 1 {
            return None;
        }
        match u16_at(entry + 2)? {
            // SHORT, the type the standard gives the tag.
            3 => u16_at(entry + 8),
            // LONG, which some writers use.
            4 => u16::try_from(u32_at(entry + 8)?).ok(),
            _ => None,
        }
    })
}

/// A still as a one-frame video stream at time zero, for hosts that open every visual source as
/// a [`Decoder`].
#[derive(Debug)]
pub struct StillStream {
    frame: DecodedVideoFrame,
    info: [StreamInfo; 1],
    given: bool,
}

impl StillStream {
    /// Decodes the still at `path`.
    ///
    /// # Errors
    /// What [`decode_still`] refuses; read failures.
    pub fn open(path: &std::path::Path) -> Result<Self, DecodeError> {
        let bytes = std::fs::read(path).map_err(|error| DecodeError::Adapter(error.to_string()))?;
        let still = decode_still(&bytes)?;
        let info = StreamInfo {
            index: 0,
            kind: StreamKind::Video,
            codec: still.info.format.as_str().to_lowercase(),
            duration: None,
            dimensions: Some((still.info.width, still.info.height)),
            frame_rate: None,
            sample_rate: None,
            channels: None,
            orientation: still.info.orientation,
            sample_aspect_ratio: SampleAspectRatio::default(),
            color: None,
            frame_bytes: None,
            alpha: None,
            language: None,
            title: None,
        };
        Ok(Self {
            frame: still.into_video_frame(),
            info: [info],
            given: false,
        })
    }
}

impl Decoder for StillStream {
    fn streams(&self) -> &[StreamInfo] {
        &self.info
    }

    fn flush(&mut self) -> Result<(), DecodeError> {
        self.given = false;
        Ok(())
    }

    fn seek(
        &mut self,
        request: DecodeRequest,
        cancel: &CancelToken,
    ) -> Result<DecodeResult, DecodeError> {
        if cancel.is_cancelled() {
            return Err(DecodeError::Cancelled);
        }
        self.given = true;
        Ok(DecodeResult {
            request,
            event: DecodeEvent::Video(self.frame.clone()),
        })
    }

    fn decode_next(&mut self, cancel: &CancelToken) -> Result<DecodeEvent, DecodeError> {
        if cancel.is_cancelled() {
            return Err(DecodeError::Cancelled);
        }
        if std::mem::replace(&mut self.given, true) {
            return Ok(DecodeEvent::EndOfStream);
        }
        Ok(DecodeEvent::Video(self.frame.clone()))
    }
}

#[cfg(test)]
#[path = "stills_tests.rs"]
mod tests;