havok_serde/lib.rs
1// SPDX-License-Identifier: Apache-2.0 OR MIT
2//
3// The following code was written by modifying serde ver. 1.0.202.
4// See: https://github.com/serde-rs/serde/commit/58b3af4c2915c3ae789778a11f3b7a468c1cec17
5//
6// And serde holds the same license as Rust. https://github.com/rust-lang/rust/pull/43498
7//
8// The default implementation does not fully express Havok's special XML format.
9//
10// # Modification details
11// - Rust std types -> Havok Types
12// - Changed serde method to Havok XML& binary data signatures, which are easier to modify.
13//! Forked serde to serialize and deserialize Havok Class.
14
15// Restrictions
16#![deny(clippy::question_mark_used)] // Speed up compilation by eliminating inference with `?`. Use instead of `tri!`
17// Rustc lints.
18#![deny(missing_docs, unused_imports)]
19
20////////////////////////////////////////////////////////////////////////////////
21
22#[cfg(feature = "alloc")]
23extern crate alloc;
24
25/// A facade around all the types we need from the `std`, `core`, and `alloc`
26/// crates. This avoids elaborate import wrangling having to happen in every
27/// module.
28mod lib {
29 mod core {
30 #[cfg(not(feature = "std"))]
31 pub use core::*;
32 #[cfg(feature = "std")]
33 pub use std::*;
34 }
35
36 pub use self::core::f32;
37 pub use self::core::str;
38
39 pub use self::core::clone;
40 pub use self::core::convert;
41 pub use self::core::default;
42 pub use self::core::marker;
43 pub use self::core::option;
44 pub use self::core::ptr;
45 pub use self::core::result;
46
47 pub use self::core::cmp;
48 pub use self::core::fmt;
49 pub use self::core::fmt::Display;
50 pub use self::core::marker::PhantomData;
51 pub use self::core::mem;
52
53 #[cfg(all(feature = "alloc", not(feature = "std")))]
54 pub use alloc::vec::Vec;
55 #[cfg(feature = "std")]
56 pub use std::vec::Vec;
57}
58
59// None of this crate's error handling needs the `From::from` error conversion
60// performed implicitly by the `?` operator or the standard library's `try!`
61// macro. This simplified macro gives a 5.5% improvement in compile time
62// compared to standard `try!`, and 9% improvement compared to `?`.
63macro_rules! tri {
64 ($expr:expr) => {
65 match $expr {
66 Ok(val) => val,
67 Err(err) => return Err(err),
68 }
69 };
70}
71
72////////////////////////////////////////////////////////////////////////////////
73
74pub mod de;
75pub mod ser;
76
77// Used by generated code and doc tests. Not public API.(For derive)
78#[doc(hidden)]
79#[path = "private/mod.rs"]
80pub mod __private;
81
82pub use de::{Deserialize, Deserializer};
83pub use ser::Serialize;
84
85use havok_types::Signature;
86use lib::*;
87
88/// Trait whether it is Havok Class or not.
89///
90/// # Purpose
91/// This tray exists for the following purposes.
92/// - Writing `__classnames__` sections when creating binary data.
93/// - (De)Serialization process for array classes.
94pub trait HavokClass {
95 /// Get Class name.
96 fn name(&self) -> &'static str;
97 /// Get signature.
98 fn signature(&self) -> Signature;
99
100 /// Get dependencies class of indexes to do topological sort.
101 fn deps_indexes(&self) -> Vec<usize>;
102}