Skip to main content

Crate twig_sys

Crate twig_sys 

Source
Expand description

Low-level FFI bindings for Twig’s C ABI, plus the build script that links the native libtwig.a.

This crate is the -sys layer: it exposes the raw extern "C" functions, the #[repr(C)] type mirrors, and the status/format constants, and nothing else. The safe, ergonomic API lives in the twig-doc crate, which depends on this one. Direct use is unsafe and unstable across ABI-version bumps — see TWIG_ABI_VERSION.

Structs§

TwigChange
C ABI mirror of Zig’s TwigChange — the byte effect of an edit. old_span is the replaced range in the pre-edit source; new_span is the range the replacement occupies in the post-edit source (same start).
TwigFlatNode
C ABI mirror of Zig’s TwigFlatNode — one node of the editor’s flat tree snapshot. Link fields (parent/first_child/next_sibling) are ids or TWIG_NO_NODE. content_span is meaningful only when has_content_span. kind is static, library-owned storage; text/destination pointers borrow the current parse’s payloads (NULL when the kind carries none). head/alignment carry a row/cell payload, each -1 for a kind that has none (see TWIG_HEAD_NONE / TWIG_ALIGN_NONE). name_ptr is a generic container’s name — an HTML/XML tag or a directive’s type — and NULL for every other kind; directive_form is a TWIG_DIRECTIVE_NONE-defaulted code for which of the three surface forms it took; container_origin is a TWIG_CONTAINER_ORIGIN_NONE-defaulted code for whether it was WRITTEN as a tag or a directive (the two questions are different — see the constants); attrs_ptr points at attrs_len TwigKeyVals (NULL/0 when the node has no attributes). Both borrow the current parse’s payloads with the same lifetime as text_ptr.
TwigKeyVal
C ABI mirror of Zig’s TwigKeyVal — one (key, value) attribute pair. Used on the read path (TwigFlatNode::attrs_ptr, borrowed) and the write path (twig_builder_set_attrs, copied). A NULL value is a bare attribute.
TwigLanguageVTable
Mirrors TwigLanguageVTable in twig.h.
TwigQueryMatch
C ABI mirror of Zig’s TwigQueryMatch — one node returned by twig_document_query. content_span is only meaningful when has_content_span is non-zero. kind is a NUL-terminated node-kind name in static, library-owned storage (never freed).
TwigSpan
C ABI mirror of Zig’s TwigSpan — a byte range [start, end).
TwigStatus
TwigTransport
Mirrors TwigTransport in twig.h: one line of the helper wire traded for another. The library speaks the wire; the host moves the lines.
TwigWarning
C ABI mirror of Zig’s TwigWarning — one thing a conversion would silently lose. path is a slash-separated child-index trail from the analyzed root (empty for the root itself); kind is a NUL-terminated node-kind name in static, library-owned storage. Both borrow, with the lifetime of the twig_document_diagnostics output array they came from.

Enums§

TwigBuilder
TwigDocument
TwigEditor
TwigFormat

Constants§

TWIG_ABI_VERSION
The C ABI contract version this binding is written against; see twig_abi_version. Must match the value baked into the linked library (asserted at runtime by the abi_version_matches test in lib.rs).
TWIG_ALIGN_CENTER
TWIG_ALIGN_DEFAULT
TWIG_ALIGN_LEFT
TWIG_ALIGN_NONE
TwigFlatNode::alignment codes; NONE means the node isn’t a cell. NONE is part of the ABI contract even though Alignment::from_c folds it into its catch-all, so spell it out rather than leaving the -1 a mystery.
TWIG_ALIGN_RIGHT
TWIG_CONTAINER_ORIGIN_DIRECTIVE
TWIG_CONTAINER_ORIGIN_ELEMENT
TWIG_CONTAINER_ORIGIN_NONE
TwigFlatNode::container_origin codes — whether a generic container was WRITTEN as a tag or as a directive.
TWIG_DIRECTIVE_CONTAINER
TWIG_DIRECTIVE_LEAF
TWIG_DIRECTIVE_NONE
TwigFlatNode::directive_form codes — the generic-directives proposal’s three spellings: :name[x] (text), ::name{…} (leaf), :::name{…} … ::: (container). These double as twig_builder_add_directive’s form argument. NONE means the node isn’t a directive at all; like TWIG_ALIGN_NONE it is a read-path-only code, never something you can build with.
TWIG_DIRECTIVE_TEXT
TWIG_FIDELITY_ATTRS_DEGRADED
TWIG_FIDELITY_ATTRS_DROPPED
TWIG_FIDELITY_DEGRADED
TWIG_FIDELITY_DROPPED
TWIG_FIDELITY_FAITHFUL
TwigWarning::fidelity codes. FAITHFUL completes the space and is never the value of a reported warning — a faithful node is not a warning.
TWIG_FORMAT_RUNTIME_BASE
TWIG_FORMAT_RUNTIME_BASE: the first format code that names a language registered at runtime rather than compiled in — handed out by twig_language_register, per process, never pinned. Every TwigFormat member is below it, and a code in the range that no registration holds is refused with TWIG_STATUS_UNSUPPORTED_FORMAT.
TWIG_HEAD_NONE
TwigFlatNode::head for a node that is neither a row nor a cell.
TWIG_LANGUAGE_VTABLE_VERSION
Bumped only when a field of TwigLanguageVTable changes meaning.
TWIG_MD_DIRECTIVES
Markdown extension flags for the md_flags bitmask of twig_parse_ext and twig_editor_create_ext.
TWIG_MD_HIGHLIGHT
TWIG_MD_HIGHLIGHT_COLORS
TWIG_MD_HTML_ELEMENTS
TWIG_MD_MATH
TWIG_NO_NODE
The sentinel node_id for “no such node” in a TwigFlatNode link field.
TWIG_TABLE_DELETE_COLUMN
TWIG_TABLE_DELETE_ROW
TWIG_TABLE_INSERT_COLUMN
TWIG_TABLE_INSERT_ROW
TWIG_TABLE_MOVE_COLUMN
TWIG_TABLE_MOVE_ROW
TWIG_TABLE_SET_ALIGNMENT
TWIG_TASK_CHECKED_NONE
TwigFlatNode::checked for a node that is not a task_list_item.
TWIG_TRANSPORT_VERSION
Bumped only when a field of TwigTransport changes meaning.

Functions§

twig_abi_version⚠
twig_builder_add⚠
twig_builder_add_bullet_list⚠
twig_builder_add_cell⚠
twig_builder_add_cell_spanning⚠
twig_builder_add_citation⚠
twig_builder_add_code_block⚠
twig_builder_add_directive⚠
twig_builder_add_element⚠
twig_builder_add_footnote⚠
twig_builder_add_heading⚠
twig_builder_add_image⚠
twig_builder_add_link⚠
twig_builder_add_metadata⚠
twig_builder_add_ordered_list⚠
twig_builder_add_processing_instruction⚠
twig_builder_add_raw_block⚠
twig_builder_add_raw_inline⚠
twig_builder_add_reference⚠
twig_builder_add_row⚠
twig_builder_add_smart_punctuation⚠
twig_builder_add_substitution⚠
twig_builder_add_task_list⚠
twig_builder_add_task_list_item⚠
twig_builder_add_text⚠
twig_builder_ast_json⚠
twig_builder_create⚠
twig_builder_destroy⚠
twig_builder_query⚠
twig_builder_render_html⚠
twig_builder_serialize⚠
twig_builder_set_attrs⚠
twig_builder_set_children⚠
twig_document_ast_json⚠
twig_document_attrs_span⚠
twig_document_blank_line_prefix⚠
twig_document_cell_colspan⚠
twig_document_cell_rowspan⚠
twig_document_children⚠
twig_document_continuation_prefix⚠
twig_document_definitions⚠
twig_document_destroy⚠
twig_document_diagnostics⚠
twig_document_line_prefix⚠
twig_document_node_at⚠
twig_document_node_at_caret⚠
twig_document_node_content_span⚠
twig_document_node_marker_span⚠
twig_document_node_span⚠
twig_document_nodes⚠
twig_document_nodes_at⚠
twig_document_nodes_at_caret⚠
twig_document_query⚠
twig_document_render_html⚠
twig_document_serialize⚠
twig_document_subtree⚠
twig_editor_ast_json⚠
twig_editor_caret_blob⚠
twig_editor_child_spans⚠
twig_editor_clear_dirty⚠
twig_editor_coalesce_last⚠
twig_editor_create⚠
twig_editor_create_ext⚠
twig_editor_delete⚠
twig_editor_delete_smart⚠
twig_editor_destroy⚠
twig_editor_dirty_range⚠
twig_editor_document⚠
twig_editor_edit_range⚠
twig_editor_filter⚠
twig_editor_insert_after⚠
twig_editor_insert_before⚠
twig_editor_insert_child⚠
twig_editor_insert_directive⚠
twig_editor_insert_display_math⚠
twig_editor_insert_footnote⚠
twig_editor_insert_image⚠
twig_editor_insert_inline_math⚠
twig_editor_insert_line_break⚠
twig_editor_insert_link⚠
twig_editor_insert_literal⚠
twig_editor_insert_table⚠
twig_editor_insert_thematic_break⚠
twig_editor_join_blocks⚠
twig_editor_last_change⚠
twig_editor_move_after⚠
twig_editor_move_before⚠
twig_editor_move_block⚠
twig_editor_node_at⚠
twig_editor_nodes⚠
twig_editor_nodes_at⚠
twig_editor_query⚠
twig_editor_redo⚠
twig_editor_renumber_ordered_lists⚠
twig_editor_replace⚠
twig_editor_replace_content⚠
twig_editor_revision⚠
twig_editor_set_block⚠
twig_editor_set_block_attrs⚠
twig_editor_set_caret_blob⚠
twig_editor_set_code_language⚠
twig_editor_set_mark_color⚠
Set — or clear, with has_color == 0 — the colour of the highlight the caret at offset is inside. Markdown with TWIG_MD_HIGHLIGHT_COLORS only; the name is a data-color value (red, blue, …).
twig_editor_set_node_attrs⚠
twig_editor_set_task_checked⚠
twig_editor_source⚠
twig_editor_split_block⚠
twig_editor_subtree⚠
twig_editor_table_edit⚠
twig_editor_toggle_block_container⚠
twig_editor_toggle_code_block⚠
twig_editor_toggle_inline⚠
twig_editor_toggle_task_checked⚠
twig_editor_toggle_task_item⚠
twig_editor_undo⚠
twig_editor_unwrap⚠
twig_editor_wrap_range⚠
twig_editor_wrap_range_attrs⚠
twig_format_by_name⚠
twig_format_is_authorable⚠
Whether format can be authored into at all — 0 for a parse-only format. A weaker claim than it looks; see twig_format_supports.
twig_format_name⚠
twig_format_supports⚠
Whether format can spell gesture — the toolbar’s gray-out question, asked without a document. kind is read in that gesture’s own kind space (a TWIG_GESTURE_* doc comment in twig.h lists which), and must be 0 for a gesture that takes none.
twig_format_supports_ext⚠
twig_format_supports for a document parsed with md_flags — the question asked of the table the editor actually holds. A Markdown extension can widen what may be authored: ==x== is text under default options and a mark under TWIG_MD_HIGHLIGHT, and TWIG_GESTURE_SET_MARK_COLOR needs TWIG_MD_HIGHLIGHT_COLORS on top.
twig_language_register⚠
twig_language_register_transport⚠
twig_parse⚠
twig_parse_ext⚠
twig_version⚠
twig_version_string⚠

Type Aliases§

TwigLanguageFn
A language function: input in, and on success an allocation of the host’s out through out/out_len, returning 0. On failure it returns non-zero and may hand out a UTF-8 message the same way. Twig releases whatever it hands out with the table’s free.