ogmo3/
lib.rs

1//! `ogmo3` is a Rust crate for parsing projects and levels created with [Ogmo Editor 3](https://ogmo-editor-3.github.io/).
2
3#![warn(missing_docs)]
4
5pub mod level;
6pub mod project;
7
8use std::error::Error as StdError;
9use std::fmt::{self, Display, Formatter};
10use std::io;
11
12use serde::{Deserialize, Serialize};
13
14pub use level::{Layer, Level, Value};
15pub use project::Project;
16
17/// The various kinds of errors that can occur while parsing Ogmo data.
18#[derive(Debug)]
19pub enum Error {
20    /// An IO error was encountered.
21    Io(io::Error),
22
23    /// An error was encountered while deserializing JSON.
24    Json(serde_json::Error),
25}
26
27impl Display for Error {
28    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
29        match self {
30            Error::Io(_) => write!(f, "IO error"),
31            Error::Json(_) => write!(f, "JSON error"),
32        }
33    }
34}
35
36impl StdError for Error {
37    fn source(&self) -> Option<&(dyn StdError + 'static)> {
38        match self {
39            Error::Io(cause) => Some(cause),
40            Error::Json(cause) => Some(cause),
41        }
42    }
43}
44
45/// An X and Y value.
46#[derive(Copy, Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
47pub struct Vec2<T> {
48    /// The X component.
49    pub x: T,
50
51    /// The Y component.
52    pub y: T,
53}