ctb_formats_dcstring/
converters.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3This file is part of Collective Toolbox, a database and document workspace and utilities.
4Copyright (C) 2026 Collective Toolbox Developers
5Contact: info@collectivetoolbox.com
6
7This program is free software: you can redistribute it and/or modify it under
8the terms of the GNU Affero General Public License as published by the Free
9Software Foundation, either version 3 of the License, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License along
17with this program.  If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! Converters between DcString / DcList and various text formats (DcText, Dcal, UTF-8).
21
22#[allow(
23    unused_imports,
24    clippy::wildcard_imports,
25    reason = "Standard workspace module prelude"
26)]
27use crate::utilities::*;
28
29pub mod ascii;
30pub mod dcal;
31pub mod dctext;
32pub mod dcts;
33pub mod eite;
34pub mod transform;
35pub mod utf8;
36pub mod wasm;
37pub mod wasm_capabilities;
38pub mod wasm_quota;
39pub mod wasm_to_rust;
40pub mod wat;
41
42pub use wasm_capabilities::{
43    MAX_PURE_WASM_NESTING_DEPTH, encode_capability_error_record,
44    encode_dc_string_literal, eval_pure_graph_capability_request,
45    run_wasm_session_pure_with_graph_capabilities,
46};
47
48/// Produces DcUtf while retaining binary payload types and checksums.
49///
50/// # Errors
51/// Returns an error for invalid input or invalid encapsulation metadata.
52pub(crate) fn document_dc_string(
53    doc: &crate::DcMstr,
54) -> Result<crate::DcString> {
55    crate::validate_dcmst(doc.as_bytes())?;
56    doc.to_dc_string()
57}
58
59pub use ascii::{
60    AsciiSettings, AsciiUnmappablePolicy, ascii_safe_subset_to_dcmstring,
61    ascii_safe_subset_to_dcmstring_with_settings, ascii_to_dcmstring,
62    ascii_to_dcmstring_with_settings, dcmstring_to_ascii,
63    dcmstring_to_ascii_safe_subset,
64    dcmstring_to_ascii_safe_subset_with_settings,
65    dcmstring_to_ascii_with_settings,
66};
67pub use dcal::{dcal_to_dclist, dclist_to_dcal};
68pub use dctext::{
69    DcList, dcarray_to_dclist, dcarray_to_dcstring, dcarray_to_dctext,
70    dclist_to_dcarray, dclist_to_dctext, dclist_to_dcutf, dcstring_to_dcarray,
71    dcstring_to_dctext, dctext_to_dcarray, dctext_to_dclist,
72    dctext_to_dcstring, dctext_to_dctf, dctext_to_dcutf, dctf_to_dctext,
73    dcutf_to_dclist, dcutf_to_dctext, format_blob_preview,
74};
75pub use dcts::{
76    dcarray_to_dcts, dclist_to_dcts, dcstring_to_dcts, dcts_to_dcarray,
77    dcts_to_dclist, dcts_to_dcstring, dcts_to_dcutf, dcutf_to_dcts,
78};
79pub use transform::{
80    apply_dc_transformation, apply_dc_transformations,
81    transform_dclist_unicode_to_short_dc,
82};
83pub use utf8::{
84    DcListUtf8Settings, dclist_from_utf8, dclist_to_utf8, utf8_to_dclist,
85};
86pub use wasm::{
87    DC_WASM_MAILBOX_HEADER_LEN, DC_WASM_MAILBOX_INPUT_LEN,
88    DC_WASM_MAILBOX_INPUT_PTR, DC_WASM_MAILBOX_MOST_RECENT_NODE_ID,
89    DC_WASM_MAILBOX_OUTPUT_LEN, DC_WASM_MAILBOX_OUTPUT_PTR,
90    DEFAULT_MAX_WASM_INSTRUCTIONS_PER_STEP, DEFAULT_MAX_WASM_MEMORY_PAGES,
91    DEFAULT_MAX_WASM_SESSION_OUTPUT_BYTES, DEFAULT_MAX_WASM_STEP_OUTPUT_BYTES,
92    DEFAULT_MAX_WASM_TABLE_ELEMENTS, DcWasmResourceLimits, DcWasmSession,
93    InstrumentedWasmModule, SharedWasmTaskQuota, SharedWasmTaskQuotaState,
94    WasmResourceInterruption, WasmStepOutcome, WasmStepStatus,
95    assemble_wasm_instructions, dcmstring_to_wasm,
96    dcmstring_to_wasm_with_resolver, dcstring_to_wasm,
97    dcstring_to_wasm_with_resolver, instrument_wasm_module_bytes,
98    run_dc_wasm_pure_conversion, run_dc_wasm_pure_conversion_with_resolver,
99    run_graph_wasm_tokens_on_dc_slice,
100    run_graph_wasm_tokens_on_dc_slice_with_quota,
101};
102pub use wat::{
103    wat_to_dc_shorthand_string, wat_to_dc_shorthands, wat_to_dclist,
104    wat_to_dcmstring, wat_to_dcmstring_with_resolver, wat_to_dcstring,
105    wat_to_wasm, wat_to_wasm_with_resolver,
106};