quake_map/lib.rs
1//! Quake source map data structures, parsing, and writing
2//!
3//! # Example
4//!
5//!```
6//! # use std::ffi::CString;
7//! # use std::io::Read;
8//! #
9//! #
10//! # fn main() -> Result<(), String> {
11//! # #[cfg(feature="std")]
12//! # {
13//! # let mut source = &b"
14//! # {
15//! # }
16//! # "[..];
17//! #
18//! # let mut dest = Vec::<u8>::new();
19//! #
20//! use quake_map::{Entity, WriteError, TextParseError};
21//!
22//! let mut map = quake_map::parse(&mut source).map_err(|err| match err {
23//! TextParseError::Io(_) => String::from("Failed to read map"),
24//! l_err@TextParseError::Lexer(_) => l_err.to_string(),
25//! p_err@TextParseError::Parser(_) => p_err.to_string(),
26//! })?;
27//!
28//! let mut soldier = Entity::new();
29//!
30//! soldier.edict.push((
31//! CString::new("classname").unwrap(),
32//! CString::new("monster_army").unwrap(),
33//! ));
34//!
35//! soldier.edict.push((
36//! CString::new("origin").unwrap(),
37//! CString::new("128 -256 24").unwrap(),
38//! ));
39//!
40//! map.entities.push(soldier);
41//!
42//! map.write_to(&mut dest).map_err(|err| match err {
43//! WriteError::Io(e) => e.to_string(),
44//! WriteError::Validation(msg) => msg
45//! })?;
46//! #
47//! # }
48//! # Ok(())
49//! # }
50//!```
51
52#![no_std]
53
54#[cfg(feature = "std")]
55#[macro_use]
56extern crate std;
57
58#[cfg(not(feature = "std"))]
59extern crate alloc;
60
61mod error;
62
63#[cfg(feature = "std")]
64pub use error::TextParse as TextParseError;
65
66#[cfg(feature = "std")]
67pub use error::TextParseResult;
68
69#[cfg(feature = "std")]
70pub use error::Write as WriteError;
71
72#[cfg(feature = "std")]
73pub use error::WriteResult;
74
75pub use error::Validation as ValidationError;
76pub use error::ValidationResult;
77
78mod repr;
79
80#[cfg(feature = "std")]
81mod lexer;
82
83#[cfg(feature = "std")]
84mod parser;
85
86pub use repr::*;
87
88#[cfg(feature = "std")]
89pub use parser::parse;
90
91// test suites
92
93#[cfg(all(test, feature = "std"))]
94mod parser_test;
95
96#[cfg(all(test, feature = "std"))]
97mod lexer_test;
98
99#[cfg(test)]
100mod repr_test;