gvdb/lib.rs
1//! # Read and write GVDB files
2//!
3//! This crate allows you to read and write GVDB (GLib GVariant database) files.
4//! It can also parse GResource XML files and create the corresponding GResource binary
5//!
6//! ## Examples
7//!
8//! Load a GResource file from disk with [`File`](crate::read::File)
9//!
10//! ```
11//! use std::path::PathBuf;
12//! use gvdb::read::File;
13//!
14//! pub fn read_gresource_file() {
15//! let path = PathBuf::from("test-data/test3.gresource");
16//! let file = File::from_file(&path).unwrap();
17//! let table = file.hash_table().unwrap();
18//!
19//! #[derive(serde::Deserialize, zvariant::Type, zvariant::OwnedValue)]
20//! struct SvgData {
21//! size: u32,
22//! flags: u32,
23//! content: Vec<u8>
24//! }
25//!
26//! let svg: SvgData = table
27//! .get("/gvdb/rs/test/online-symbolic.svg")
28//! .unwrap();
29//! let svg_str = std::str::from_utf8(&svg.content).unwrap();
30//!
31//! println!("{}", svg_str);
32//! }
33//! ```
34//!
35//! Create a simple GVDB file with [`FileWriter`](crate::write::FileWriter)
36//!
37//! ```
38//! use gvdb::write::{FileWriter, HashTableBuilder};
39//!
40//! fn create_gvdb_file() {
41//! let mut file_writer = FileWriter::new();
42//! let mut table_builder = HashTableBuilder::new();
43//! table_builder
44//! .insert_string("string", "test string")
45//! .unwrap();
46//!
47//! let mut table_builder_2 = HashTableBuilder::new();
48//! table_builder_2
49//! .insert("int", 42u32)
50//! .unwrap();
51//!
52//! table_builder
53//! .insert_table("table", table_builder_2)
54//! .unwrap();
55//! let file_data = file_writer.write_to_vec_with_table(table_builder).unwrap();
56//! }
57//! ```
58//!
59//! ## Features
60//!
61//! By default, no features are enabled.
62//!
63//! ### `mmap`
64//!
65//! Use the memmap2 crate to read memory-mapped GVDB files.
66//!
67//! ### `glib`
68//!
69//! By default this crate uses the [glib](https://crates.io/crates/zvariant) crate to allow reading
70//! and writing `GVariant` data to the gvdb files. By enabling this feature you can pass GVariants
71//! directly from the glib crate as well.
72//!
73//! ### `gresource`
74//!
75//! To be able to compile GResource files, the `gresource` feature must be enabled.
76//!
77//! ## Macros
78//!
79//! The [gvdb-macros](https://crates.io/crates/gvdb-macros) crate provides useful macros for
80//! GResource file creation.
81
82#![warn(missing_docs)]
83#![allow(unknown_lints, clippy::assigning_clones)]
84#![doc = include_str!("../README.md")]
85
86extern crate core;
87
88/// Read GResource XML files and compile a GResource file
89///
90/// Use [`XmlManifest`](crate::gresource::XmlManifest) for XML file reading and
91/// [`BundleBuilder`](crate::gresource::BundleBuilder) to create the GResource binary
92/// file
93#[cfg(feature = "gresource")]
94pub mod gresource;
95
96/// Read GVDB files from a file or from a byte slice
97///
98/// See the documentation of [`File`](crate::read::File) to get started
99pub mod read;
100
101/// Create GVDB files
102///
103/// See the documentation of [`FileWriter`](crate::write::FileWriter) to get started
104pub mod write;
105
106/// Serialize types as GVariant
107pub mod variant;
108
109#[cfg(test)]
110pub(crate) mod test;
111
112mod endian;
113mod util;
114
115pub(crate) use endian::Endian;