Skip to main content

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
61#[cfg(feature = "std")]
62mod error;
63
64#[cfg(feature = "std")]
65pub use error::TextParse as TextParseError;
66
67#[cfg(feature = "std")]
68pub use error::Write as WriteError;
69
70#[cfg(feature = "std")]
71pub type TextParseResult<T> = Result<T, TextParseError>;
72
73#[cfg(feature = "std")]
74pub type WriteAttempt = Result<(), WriteError>;
75
76mod repr;
77
78#[cfg(feature = "std")]
79mod lexer;
80
81#[cfg(feature = "std")]
82mod parser;
83
84pub use repr::{
85    Alignment, Brush, CheckWritable, Edict, Entity, EntityKind, HalfSpace,
86    Point, QuakeMap, Surface, ValidationResult, Vec2, Vec3,
87};
88
89#[cfg(feature = "std")]
90pub use parser::parse;
91
92// test suites
93
94#[cfg(all(test, feature = "std"))]
95mod parser_test;
96
97#[cfg(all(test, feature = "std"))]
98mod lexer_test;
99
100#[cfg(test)]
101mod repr_test;