Crate libyml

Source
Expand description

§LibYML (a fork of unsafe-libyaml)

Made With Love Crates.io lib.rs Docs.rs Codecov Build Status GitHub

LibYML is a Rust library for working with YAML data, forked from unsafe-libyaml. It offers a safe and efficient interface for parsing, emitting, and manipulating YAML data.

§Features

  • Serialization and Deserialization: Easy-to-use APIs for serializing Rust structs and enums to YAML and vice versa.
  • Custom Struct and Enum Support: Seamless serialization and deserialization of custom data types.
  • Comprehensive Error Handling: Detailed error messages and recovery mechanisms.
  • Streaming Support: Efficient processing of large YAML documents.
  • Alias and Anchor Support: Handling of complex YAML structures with references.
  • Tag Handling: Support for custom tags and type-specific serialization.
  • Configurable Emitter: Customizable YAML output generation.
  • Extensive Documentation: Detailed docs and examples for easy onboarding.
  • Safety and Efficiency: Minimized unsafe code with an interface designed to prevent common pitfalls.

§Installation

Add this to your Cargo.toml:

[dependencies]
libyml = "0.0.5"

§Documentation

For full API documentation, please visit https://doc.libyml.com/libyml/ or https://docs.rs/libyml.

§Rust Version Compatibility

Compiler support: requires rustc 1.56.0+

§Contributing

Contributions are welcome! If you’d like to contribute, please feel free to submit a Pull Request on GitHub.

§Credits and Acknowledgements

LibYML is a fork of the work done by David Tolnay and the maintainers of unsafe-libyaml. While it has evolved into a separate library, we express our sincere gratitude to them as well as the libyaml maintainers for their contributions to the Rust and C programming communities.

§License

MIT license, same as libyaml.

Re-exports§

pub use crate::api::yaml_alias_event_initialize;
pub use crate::api::yaml_emitter_delete;
pub use crate::api::yaml_emitter_initialize;
pub use crate::api::yaml_emitter_set_break;
pub use crate::api::yaml_emitter_set_canonical;
pub use crate::api::yaml_emitter_set_encoding;
pub use crate::api::yaml_emitter_set_indent;
pub use crate::api::yaml_emitter_set_output;
pub use crate::api::yaml_emitter_set_output_string;
pub use crate::api::yaml_emitter_set_unicode;
pub use crate::api::yaml_emitter_set_width;
pub use crate::api::yaml_event_delete;
pub use crate::api::yaml_mapping_end_event_initialize;
pub use crate::api::yaml_mapping_start_event_initialize;
pub use crate::api::yaml_parser_set_encoding;
pub use crate::api::yaml_parser_set_input;
pub use crate::api::yaml_parser_set_input_string;
pub use crate::api::yaml_scalar_event_initialize;
pub use crate::api::yaml_sequence_end_event_initialize;
pub use crate::api::yaml_sequence_start_event_initialize;
pub use crate::api::yaml_stream_end_event_initialize;
pub use crate::api::yaml_stream_start_event_initialize;
pub use crate::api::yaml_token_delete;
pub use crate::decode::yaml_parser_delete;
pub use crate::decode::yaml_parser_initialize;
pub use crate::document::yaml_document_delete;
pub use crate::document::yaml_document_get_node;
pub use crate::document::yaml_document_get_root_node;
pub use crate::document::yaml_document_initialize;
pub use crate::dumper::yaml_emitter_close;
pub use crate::dumper::yaml_emitter_dump;
pub use crate::dumper::yaml_emitter_open;
pub use crate::loader::yaml_parser_load;
pub use crate::yaml::YamlAliasDataT;
pub use crate::yaml::YamlBreakT;
pub use crate::yaml::YamlDocumentT;
pub use crate::yaml::YamlEmitterStateT;
pub use crate::yaml::YamlEmitterT;
pub use crate::yaml::YamlEncodingT;
pub use crate::yaml::YamlErrorTypeT;
pub use crate::yaml::YamlEventT;
pub use crate::yaml::YamlEventTypeT;
pub use crate::yaml::YamlMappingStyleT;
pub use crate::yaml::YamlMarkT;
pub use crate::yaml::YamlNodeItemT;
pub use crate::yaml::YamlNodePairT;
pub use crate::yaml::YamlNodeT;
pub use crate::yaml::YamlNodeTypeT;
pub use crate::yaml::YamlParserStateT;
pub use crate::yaml::YamlParserT;
pub use crate::yaml::YamlReadHandlerT;
pub use crate::yaml::YamlScalarStyleT;
pub use crate::yaml::YamlSequenceStyleT;
pub use crate::yaml::YamlSimpleKeyT;
pub use crate::yaml::YamlStackT;
pub use crate::yaml::YamlTagDirectiveT;
pub use crate::yaml::YamlTokenT;
pub use crate::yaml::YamlTokenTypeT;
pub use crate::yaml::YamlVersionDirectiveT;
pub use crate::yaml::YamlWriteHandlerT;

Modules§

api
API module for LibYML.
decode
Decode module for LibYML.
document
Document module for LibYML.
dumper
Dumper module for LibYML.
externs
Extern functions and macros for interacting with the underlying libyaml C library.
internal
Internal utilities for LibYML.
libc
Declarations for C library functions used within the LibYML library.
loader
Loader module for LibYML.
macros
Macros module for LibYML.
memory
Memory management for LibYML.
string
String utilities for LibYML.
success
Success and Failure types for LibYML.
utils
Utility functions for LibYML.
yaml
YAML API module for LibYML.

Macros§

AS_DIGIT
Converts the byte at the current pointer in the string to its corresponding integer value.
AS_HEX_AT
Converts a hexadecimal character at a given offset in a string to its corresponding integer value.
BUFFER_DEL
Deletes the buffer and frees the allocated memory.
BUFFER_INIT
Initializes a buffer with a given size.
CHECK
A macro that checks if the current byte in the given string matches a specific octet.
CHECK_AT
This macro checks if the octet at the specified offset in the given string matches the provided octet.
CLEAR
Clears the content of the string by setting the pointer to the start and filling the memory from the start to the end with zeros.
DEQUEUE
Removes and returns the first element from the queue.
ENQUEUE
Enqueues a value onto the queue.
IS_ALPHA
Checks if the current character in the string is an alphabetic character.
IS_ASCII
Checks if the current character in the string is an ASCII character.
IS_BLANK
Checks if the character at the current pointer in the given string is a space or tab character.
IS_BLANKZ
Checks if the character at the current pointer in the given string is a space, tab, line break character, or if it is a null character.
IS_BLANKZ_AT
Checks if the character at the specified offset in the given string is a space, tab, or line break character, or if it is a null character.
IS_BLANK_AT
Checks if the character at the specified offset in the given string is a space or tab character.
IS_BOM
Checks if the first three bytes of the given string form the UTF-8 byte order mark (BOM) for UTF-8 encoding.
IS_BREAK
Checks if the character at the current pointer in the given string is a line break character.
IS_BREAKZ
Checks if the character at the current pointer in the given string is a line break character or a null character.
IS_BREAKZ_AT
Checks if the character at the specified offset in the given string is a line break character or a null character.
IS_BREAK_AT
Checks if the character at the specified offset in the given string is a line break character.
IS_CRLF
Checks if the character at the current pointer in the given string is a carriage return followed by a line feed.
IS_DIGIT
Checks if the byte pointed to by the pointer in the given string is a digit (0-9).
IS_HEX_AT
Checks if the character at the given offset in the string is a hexadecimal digit.
IS_PRINTABLE
Checks if the character at the current pointer in the given string is printable.
IS_SPACE
Checks if the character at the current pointer in the given string is a space character (ASCII 0x20).
IS_SPACE_AT
Checks if the character at the specified offset in the given string is a space character (ASCII 0x20).
IS_TAB
Checks if the character at the current pointer in the given string is a tab character (ASCII 0x09).
IS_TAB_AT
Checks if the character at the specified offset in the given string is a tab character (ASCII 0x09).
IS_Z
Checks if the character at the current pointer in the given string is a null character (ASCII 0).
IS_Z_AT
Checks if the character at the specified offset in the given string is a null character (ASCII 0).
JOIN
Joins two strings together by appending the contents of string_b to string_a.
MOVE
Moves the pointer of the given string to the next Unicode character.
POP
Removes and returns the last element from the stack.
PUSH
Pushes a value onto the stack.
QUEUE_DEL
Deallocates the memory used by the queue and sets all pointers to null.
QUEUE_EMPTY
Checks if the queue is empty.
QUEUE_INIT
Initializes a queue with a specified type and allocates memory for it.
QUEUE_INSERT
Inserts a value into the queue at the specified index.
STACK_DEL
Deallocates the memory used by the stack and sets all pointers to null.
STACK_EMPTY
Checks if the stack has no elements.
STACK_INIT
Initializes a stack with a specified type and allocates memory for it.
STACK_LIMIT
Checks if the stack has enough memory to push a new element.
STRING_ASSIGN
Assigns a new value to a YamlStringT struct.
STRING_DEL
Deletes a string and frees the allocated memory.
STRING_EXTEND
Extends the capacity of a string by reallocating memory if the current capacity is insufficient.
STRING_INIT
Initializes a string for use with the yaml library.
WIDTH
Returns the width of the Unicode character at the current position in a string.
WIDTH_AT
Returns the width of a Unicode character at the given offset in a string.
copy
Copies the content of a string to another string.
yaml_free
Frees memory allocated by yaml_malloc! or yaml_realloc!.
yaml_malloc
Allocates memory using the system’s malloc function.
yaml_realloc
Reallocates memory using the system’s realloc function.
yaml_strdup
Duplicates a string using the system’s malloc function and manual copy.

Functions§

yaml_emitter_emit
Emit an event.
yaml_emitter_flush
Flushes the buffer of the emitter and writes the content to the output stream.
yaml_parser_parse
Parse the input stream and produce the next parsing event.
yaml_parser_scan
Scan the input stream and produce the next token.