Skip to content

Commit

Permalink
remove InitError because only one variant was used
Browse files Browse the repository at this point in the history
  • Loading branch information
antonilol committed Oct 8, 2024
1 parent c4e74c7 commit d5985e3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
31 changes: 2 additions & 29 deletions src/sdl2/ttf/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,41 +91,14 @@ pub fn get_linked_version() -> Version {
Version::from_ll(unsafe { *ttf::TTF_Linked_Version() })
}

/// An error for when `sdl2_ttf` is attempted initialized twice
/// Necessary for context management, unless we find a way to have a singleton
#[derive(Debug)]
pub enum InitError {
InitializationError(String),
AlreadyInitializedError,
}

impl error::Error for InitError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
InitError::InitializationError(_) | InitError::AlreadyInitializedError => None,
}
}
}

impl fmt::Display for InitError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::AlreadyInitializedError => {
write!(f, "SDL2_TTF has already been initialized")
}
Self::InitializationError(error) => write!(f, "SDL2_TTF initialization error: {error}"),
}
}
}

/// Initializes the truetype font API and returns a context manager which will
/// clean up the library once it goes out of scope.
#[doc(alias = "TTF_Init")]
pub fn init() -> Result<Sdl2TtfContext, InitError> {
pub fn init() -> Result<Sdl2TtfContext, String> {
if unsafe { ttf::TTF_Init() } == 0 {
Ok(Sdl2TtfContext(()))
} else {
Err(InitError::InitializationError(get_error()))
Err(get_error())
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/sdl2/ttf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
mod context;
mod font;

pub use self::context::{
get_linked_version, has_been_initialized, init, InitError, Sdl2TtfContext,
};
pub use self::context::{get_linked_version, has_been_initialized, init, Sdl2TtfContext};
pub use self::font::{
Font, FontError, FontResult, FontStyle, GlyphMetrics, Hinting, PartialRendering,
};

0 comments on commit d5985e3

Please sign in to comment.