Repository: typst/typst
File: crates/typst-library/src/loading/cbor.rs (Rust)

Code before:
use ecow::eco_format;
use typst_syntax::Spanned;

use crate::diag::{At, SourceResult};
use crate::engine::Engine;
use crate::foundations::{Bytes, Value, func, scope};
use crate::loading::{DataSource, Load};

/// Reads structured data from a CBOR file.
///
/// The file must contain a valid CBOR serialization. The CBOR values will be
/// converted into corresponding Typst values listed in the
/// [table below](#conversion).
///
/// The function returns a dictionary, an array or, depending on the CBOR file,
/// another CBOR data type.
///
/// # Conversion details { #conversion }
/// Typst uses [ciborium](https://docs.rs/ciborium/latest/ciborium/#compatibility-with-other-implementations)
/// to process CBOR data. The ciborium project is wire-compatible with other
/// implementations in decoding, but not necessarily encoding.
///
/// | CBOR value | Converted into Typst   |
/// | ---------- | ---------------------- |
/// | integer    | [`int`] (or [`float`]) |
/// | bytes      | [`bytes`]              |
/// | float      | [`float`]              |
/// | text       | [`str`]                |
/// | bool       | [`bool`]               |
/// | null       | `{none}`               |
/// | array      | [`array`]              |
/// | map        | [`dictionary`]         |
///
/// - Be aware that **CBOR integers** larger than 2<sup>63</sup>-1 or smaller than
///   -2<sup>63</sup> will be approximated as floating-point numbers or rejected
///   for parsing.
///
/// - **CBOR tags** are not supported, and an error will be thrown.
///
/// | Typst value                           | Converted into CBOR          |
/// | ------------------------------------- | ---------------------------- |
/// | types that can be converted from CBOR | corresponding CBOR value     |
/// | [`symbol`]                            | text                         |
/// | [`content`]                           | a map describing the content |
/// | other types ([`length`], etc.)        | text via [`repr`]            |
///

Review comment (bug):
I see that this is written in the docs, but that seems so odd, and I'm not sure I understand the example on docs.rs with the numbers. If serde_cbor can't decode ciborium's output isn't that necessarily a bug in either one of the two?

Code after:
use ecow::eco_format;
use typst_syntax::Spanned;

use crate::diag::{At, SourceResult};
use crate::engine::Engine;
use crate::foundations::{Bytes, Value, func, scope};
use crate::loading::{DataSource, Load};

/// Reads structured data from a CBOR file.
///
/// The file must contain a valid CBOR serialization. The CBOR values will be
/// converted into corresponding Typst values as listed in the
/// [table below](#conversion).
///
/// The function returns a dictionary, an array or, depending on the CBOR file,
/// another CBOR data type.
///
/// # Conversion details { #conversion }
///
/// | CBOR value | Converted into Typst   |
/// | ---------- | ---------------------- |
/// | integer    | [`int`] (or [`float`]) |
/// | bytes      | [`bytes`]              |
/// | float      | [`float`]              |
/// | text       | [`str`]                |
/// | bool       | [`bool`]               |
/// | null       | `{none}`               |
/// | array      | [`array`]              |
/// | map        | [`dictionary`]         |
///
/// | Typst value                           | Converted into CBOR          |
/// | ------------------------------------- | ---------------------------- |
/// | types that can be converted from CBOR | corresponding CBOR value     |
/// | [`symbol`]                            | text                         |
/// | [`content`]                           | a map describing the content |
/// | other types ([`length`], etc.)        | text via [`repr`]            |
///
/// ## Notes
///
/// - Be aware that CBOR integers larger than 2<sup>63</sup>-1 or smaller than
///   -2<sup>63</sup> will be converted to floating point numbers, which may
///   result in an approximative value.
///
/// - CBOR tags are not supported, and an error will be thrown.
///
/// - The `repr` function is [for debugging purposes only]($repr/#debugging-only),