pyxel/lib.rs
1//! # Pyxel
2//!
3//! Pyxel is a library for loading [PyxelEdit](https://pyxeledit.com) documents in Rust. Current only the latest (v0.4.8) version of PyxelEdit is officially supported.
4
5#![allow(unknown_lints)]
6#![deny(clippy::all)]
7#![deny(
8 missing_docs,
9 missing_copy_implementations,
10 missing_debug_implementations
11)]
12
13use std::{fs::File, io::Cursor, path::Path};
14
15mod deserialization;
16mod error;
17mod pyxel;
18
19pub use crate::error::PyxelError;
20pub use crate::pyxel::*;
21
22/// Load a Pyxel document from a byte slice.
23///
24/// # Examples
25///
26/// ```
27/// use std::fs;
28/// # fn main() -> Result<(), pyxel::PyxelError> {
29/// let buf = fs::read("resources/doc.pyxel")?;
30/// let doc = pyxel::load_from_memory(&buf)?;
31/// # Ok(())
32/// # }
33/// ```
34pub fn load_from_memory(buf: &[u8]) -> Result<Pyxel, PyxelError> {
35 let cursor = Cursor::new(buf);
36 load(cursor)
37}
38
39/// Open the Pyxel document located at the path specified.
40///
41/// # Examples
42///
43/// ```
44/// # fn main() -> Result<(), pyxel::PyxelError> {
45/// let doc = pyxel::open("resources/doc.pyxel")?;
46/// # Ok(())
47/// # }
48/// ```
49pub fn open<P>(path: P) -> Result<Pyxel, PyxelError>
50where
51 P: AsRef<Path>,
52{
53 let file = File::open(path)?;
54 load(file)
55}