Skip to content

Commit

Permalink
error.rs: Deprecate LoadError::new()
Browse files Browse the repository at this point in the history
  • Loading branch information
simnalamburt committed Sep 28, 2024
1 parent 07ef0f6 commit acd25fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
19 changes: 14 additions & 5 deletions obj-rs/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Contains helper structs for error handling
use std::convert::From;
use std::error::Error;
use std::fmt;
use std::io;
Expand Down Expand Up @@ -100,10 +99,18 @@ pub enum LoadErrorKind {

impl LoadError {
/// Creates a new custom error from a specified kind and message.
#[deprecated(
since = "0.7.4",
note = "You shouldn’t need to create a LoadError instance on your own."
)]
pub fn new(kind: LoadErrorKind, message: &'static str) -> Self {
let message = message.to_string();
LoadError { kind, message }
}

pub(crate) fn new_internal(kind: LoadErrorKind, message: String) -> Self {
LoadError { kind, message }
}
}

impl Error for LoadError {}
Expand All @@ -129,10 +136,12 @@ impl fmt::Display for LoadError {

macro_rules! make_error {
($kind:ident, $message:expr) => {
return Err(::std::convert::From::from($crate::error::LoadError::new(
$crate::error::LoadErrorKind::$kind,
$message,
)))
return Err($crate::error::ObjError::Load(
$crate::error::LoadError::new_internal(
$crate::error::LoadErrorKind::$kind,
$message.to_string(),
),
))
};
}

Expand Down
4 changes: 2 additions & 2 deletions obj-rs/src/raw/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ impl<T: BufRead> Iterator for Lexer<T> {
let line;
match self.stripped_lines.next() {
None => {
return Some(Err(ObjError::Load(LoadError::new(
return Some(Err(ObjError::Load(LoadError::new_internal(
LoadErrorKind::BackslashAtEOF,
"Expected a line, but met an EOF",
"Expected a line, but met an EOF".to_string(),
))))
}
Some(Err(e)) => return Some(Err(ObjError::Io(e))),
Expand Down
4 changes: 2 additions & 2 deletions obj-rs/src/raw/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ fn try_index<T>(collection: &[T], input: &str) -> ObjResult<usize> {
use crate::error::{LoadError, LoadErrorKind, ObjError};

let len: isize = collection.len().try_into().map_err(|_| {
ObjError::Load(LoadError::new(
ObjError::Load(LoadError::new_internal(
LoadErrorKind::IndexOutOfRange,
"Too many items in collection",
"Too many items in collection".to_string(),
))
})?;

Expand Down

0 comments on commit acd25fc

Please sign in to comment.