fluffl/
lib.rs

1// / Module common crates that you'll probably need access to
2/// Module for playing sounds
3pub mod audio;
4/// Module for writing text to consoles
5pub mod console;
6/// Module for loading files
7pub mod io;
8
9pub mod prelude;
10/// Module for timing functions
11pub mod time;
12/// Module for creating a an opengl window
13pub mod window;
14
15/// private custom datastructures
16pub mod collections;
17/// private decodes
18pub mod decoders;
19/// private custom parsers
20mod parsers;
21mod slice;
22
23/// unsafe memory stuff
24mod mem;
25
26pub mod gui;
27
28/// private custom iterators
29mod iterators;
30
31/// math utilities
32pub mod math;
33
34/// utilities for opengl
35pub mod ogl;
36
37/// a utility module for drawing text
38pub mod text_writer; 
39
40/// Optional module for websocket clients
41#[cfg(feature="net")]
42pub mod net;
43
44/// Extras module has music playback and text-rendering routines
45/// This module is totally optional, and not really considered a part of the library
46#[cfg(feature = "extras")]
47pub mod extras;
48
49use glow::Context;
50use std::{cell::RefCell, ops::Deref, rc::Rc, sync::Arc};
51
52/// A pointer to GLOW state. All variables with this type should be named: `gl`
53pub type GlowGL = Arc<Box<Context>>;
54
55pub struct FlufflState<T> {
56    inner: Rc<RefCell<T>>,
57}
58impl<T> Clone for FlufflState<T> {
59    fn clone(&self) -> Self {
60        Self {
61            inner: self.inner.clone(),
62        }
63    }
64}
65impl<T> FlufflState<T> {
66    pub fn new(state: T) -> Self {
67        Self {
68            inner: Rc::new(RefCell::new(state)),
69        }
70    }
71}
72
73impl<T> Deref for FlufflState<T> {
74    type Target = Rc<RefCell<T>>;
75    fn deref(&self) -> &Self::Target {
76        &self.inner
77    }
78}
79
80#[derive(Debug)]
81/// A collection of Common errors that possibly could arise
82pub enum FlufflError {
83    GenericError(String),
84    FromUtf8ParseError(String),
85    WindowInitError(String),
86    IOError(String),
87}
88
89impl From<std::io::Error> for FlufflError {
90    fn from(err: std::io::Error) -> Self {
91        FlufflError::IOError(err.to_string())
92    }
93}
94
95impl From<std::string::FromUtf8Error> for FlufflError {
96    fn from(err: std::string::FromUtf8Error) -> Self {
97        Self::FromUtf8ParseError(err.to_string())
98    }
99}