regorus/utils/limits/
error.rs1#![allow(dead_code)]
5
6use core::fmt;
7use core::time::Duration;
8
9#[derive(Clone, Copy, PartialEq, Eq)]
11pub enum LimitError {
12 TimeLimitExceeded {
14 elapsed: Duration,
16 limit: Duration,
18 },
19 MemoryLimitExceeded {
21 usage: u64,
23 limit: u64,
25 },
26}
27
28impl fmt::Debug for LimitError {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 Self::TimeLimitExceeded { elapsed, limit } => f
32 .debug_struct("TimeLimitExceeded")
33 .field("elapsed", elapsed)
34 .field("limit", limit)
35 .finish(),
36 Self::MemoryLimitExceeded { usage, limit } => f
37 .debug_struct("MemoryLimitExceeded")
38 .field("usage", usage)
39 .field("limit", limit)
40 .finish(),
41 }
42 }
43}
44
45impl fmt::Display for LimitError {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 match self {
48 Self::TimeLimitExceeded { elapsed, limit } => {
49 let elapsed_ns = elapsed.as_nanos();
50 let limit_ns = limit.as_nanos();
51 write!(
52 f,
53 "execution exceeded time limit (elapsed={}ns, limit={}ns)",
54 elapsed_ns, limit_ns
55 )
56 }
57 Self::MemoryLimitExceeded { usage, limit } => {
58 write!(
59 f,
60 "execution exceeded memory limit (usage={} bytes, limit={} bytes)",
61 usage, limit
62 )
63 }
64 }
65 }
66}
67
68impl core::error::Error for LimitError {}