mirror of
https://github.com/MeiK2333/river.git
synced 2025-11-04 14:49:40 +08:00
51 lines
1.2 KiB
Rust
51 lines
1.2 KiB
Rust
use crate::river::judge_response::{JudgeResult, JudgeStatus};
|
|
use crate::river::JudgeResponse;
|
|
use libc::strerror;
|
|
use std::ffi::{CStr, NulError, OsString};
|
|
use std::fmt;
|
|
use std::io;
|
|
use std::path::PathBuf;
|
|
use std::result;
|
|
|
|
#[derive(Debug)]
|
|
pub enum Error {
|
|
CreateTempDirError(io::Error),
|
|
LanguageNotFound(i32),
|
|
FileWriteError(io::Error),
|
|
ChannelRecvError,
|
|
StringToCStringError(NulError),
|
|
OsStringToStringError(OsString),
|
|
RemoveFileError(PathBuf),
|
|
}
|
|
|
|
pub type Result<T> = result::Result<T, Error>;
|
|
|
|
pub fn errno_str(errno: Option<i32>) -> String {
|
|
match errno {
|
|
Some(no) => {
|
|
let stre = unsafe { strerror(no) };
|
|
let c_str: &CStr = unsafe { CStr::from_ptr(stre) };
|
|
c_str.to_str().unwrap().to_string()
|
|
}
|
|
_ => "Unknown Error!".to_string(),
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for Error {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
match *self {
|
|
_ => write!(f, "{:?}", self),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn system_error(err: Error) -> JudgeResponse {
|
|
JudgeResponse {
|
|
time_used: 0,
|
|
memory_used: 0,
|
|
result: JudgeResult::SystemError as i32,
|
|
errmsg: format!("{}", err).into(),
|
|
status: JudgeStatus::Ended as i32,
|
|
}
|
|
}
|