1use core::panic;
2
3use crate::{
4 program::{ExeCode, ExeResources},
5 quantity::ProcessResource,
6};
7
8#[derive(Debug)]
9pub enum CompileResult {
10 SettingError,
11 InternalError(String),
12 CompileError(String),
13 Ok(ExeCode),
14}
15
16impl CompileResult {
17 pub fn unwrap(self) -> ExeCode {
18 match self {
19 CompileResult::Ok(i) => i,
20 CompileResult::SettingError => panic!("CompileResult::SettingError is not allowed"),
21 CompileResult::InternalError(i) => {
22 panic!("CompileResult::InternalError({}) is not allowed", i)
23 }
24 CompileResult::CompileError(i) => {
25 panic!("CompileResult::CompileError({}) is not allowed", i)
26 }
27 }
28 }
29
30 pub fn is_ok(&self) -> bool {
31 match self {
32 CompileResult::Ok(_) => true,
33 _ => false,
34 }
35 }
36}
37
38impl std::fmt::Display for CompileResult {
39 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 match self {
41 CompileResult::SettingError => write!(f, "SettingError"),
42 CompileResult::InternalError(i) => write!(f, "InternalError({})", i),
43 CompileResult::CompileError(i) => write!(f, "CompileError({})", i),
44 CompileResult::Ok(_) => write!(f, "Ok"),
45 }
46 }
47}
48
49#[derive(Debug)]
50pub enum InitExeResourceResult {
51 PermissionDenied,
52 InternalError(String),
53 Ok(ExeResources),
54}
55
56impl InitExeResourceResult {
57 pub fn unwrap(self) -> ExeResources {
58 match self {
59 InitExeResourceResult::Ok(i) => i,
60 InitExeResourceResult::PermissionDenied => {
61 panic!("InitExeResourceResult::PermissionDenied is not allowed")
62 }
63 InitExeResourceResult::InternalError(i) => {
64 panic!("InitExeResourceResult::InternalError({}) is not allowed", i)
65 }
66 }
67 }
68
69 pub fn is_ok(&self) -> bool {
70 match self {
71 InitExeResourceResult::Ok(_) => true,
72 _ => false,
73 }
74 }
75}
76
77impl std::fmt::Display for InitExeResourceResult {
78 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 match self {
80 InitExeResourceResult::PermissionDenied => write!(f, "PermissionDenied"),
81 InitExeResourceResult::InternalError(i) => write!(f, "InternalError({})", i),
82 InitExeResourceResult::Ok(_) => write!(f, "Ok"),
83 }
84 }
85}
86
87#[derive(Debug)]
88pub enum RunToEndResult {
89 InternalError(String),
90 RuntimeError(ProcessResource),
91 MemoryLimitExceeded(ProcessResource),
92 TimeLimitExceeded(ProcessResource),
93 OutputLimitExceeded(ProcessResource),
94 Ok(ProcessResource),
95}
96
97impl RunToEndResult {
98 pub fn unwrap(self) -> ProcessResource {
99 match self {
100 RunToEndResult::Ok(i) => i,
101 RunToEndResult::InternalError(i) => {
102 panic!("RunToEndResult::InternalError({}) is not allowed", i)
103 }
104 RunToEndResult::RuntimeError(i) => {
105 panic!("RunToEndResult::RuntimeError({}) is not allowed", i)
106 }
107 RunToEndResult::MemoryLimitExceeded(i) => {
108 panic!("RunToEndResult::MemoryLimitExceeded({}) is not allowed", i)
109 }
110 RunToEndResult::TimeLimitExceeded(i) => {
111 panic!("RunToEndResult::TimeLimitExceeded({}) is not allowed", i)
112 }
113 RunToEndResult::OutputLimitExceeded(i) => {
114 panic!("RunToEndResult::OutputLimitExceeded({}) is not allowed", i)
115 }
116 }
117 }
118
119 pub fn is_ok(&self) -> bool {
120 match self {
121 RunToEndResult::Ok(_) => true,
122 _ => false,
123 }
124 }
125}
126
127impl std::fmt::Display for RunToEndResult {
128 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
129 match self {
130 RunToEndResult::InternalError(i) => write!(f, "InternalError({})", i),
131 RunToEndResult::RuntimeError(i) => write!(f, "RuntimeError({})", i),
132 RunToEndResult::MemoryLimitExceeded(i) => write!(f, "MemoryLimitExceeded({})", i),
133 RunToEndResult::TimeLimitExceeded(i) => write!(f, "TimeLimitExceeded({})", i),
134 RunToEndResult::Ok(i) => write!(f, "Ok({})", i),
135 RunToEndResult::OutputLimitExceeded(i) => write!(f, "OutputLimitExceeded({})", i),
136 }
137 }
138}
139
140#[derive(Debug)]
141pub enum RunWithInteractorResult {
142 InternalError(String),
143 RuntimeError(ProcessResource, ProcessResource),
144 MemoryLimitExceeded(ProcessResource, ProcessResource),
145 TimeLimitExceeded(ProcessResource, ProcessResource),
146 OutputLimitExceeded(ProcessResource, ProcessResource),
147 InteractorRuntimeError(ProcessResource, ProcessResource),
148 InteractorMemoryLimitExceeded(ProcessResource, ProcessResource),
149 InteractorTimeLimitExceeded(ProcessResource, ProcessResource),
150 InteractorOutputLimitExceeded(ProcessResource, ProcessResource),
151 Ok(ProcessResource, ProcessResource),
152}
153
154impl RunWithInteractorResult {
155 pub fn unwrap(self) -> (ProcessResource, ProcessResource) {
156 match self {
157 RunWithInteractorResult::Ok(i, j) => (i, j),
158 RunWithInteractorResult::InternalError(i) => panic!(
159 "RunWithInteractorResult::InternalError({}) is not allowed",
160 i
161 ),
162 RunWithInteractorResult::RuntimeError(i, j) => panic!(
163 "RunWithInteractorResult::RuntimeError({},{}) is not allowed",
164 i, j
165 ),
166 RunWithInteractorResult::MemoryLimitExceeded(i, j) => panic!(
167 "RunWithInteractorResult::MemoryLimitExceeded({},{}) is not allowed",
168 i, j
169 ),
170 RunWithInteractorResult::TimeLimitExceeded(i, j) => panic!(
171 "RunWithInteractorResult::TimeLimitExceeded({},{}) is not allowed",
172 i, j
173 ),
174 RunWithInteractorResult::InteractorRuntimeError(i, j) => panic!(
175 "RunWithInteractorResult::InteractorRuntimeError({},{}) is not allowed",
176 i, j
177 ),
178 RunWithInteractorResult::InteractorMemoryLimitExceeded(i, j) => panic!(
179 "RunWithInteractorResult::InteractorMemoryLimitExceeded({},{}) is not allowed",
180 i, j
181 ),
182 RunWithInteractorResult::InteractorTimeLimitExceeded(i, j) => panic!(
183 "RunWithInteractorResult::InteractorTimeLimitExceeded({},{}) is not allowed",
184 i, j
185 ),
186 RunWithInteractorResult::InteractorOutputLimitExceeded(i, j) => panic!(
187 "RunWithInteractorResult::InteractorOutputLimitExceeded({},{}) is not allowed",
188 i, j
189 ),
190 RunWithInteractorResult::OutputLimitExceeded(i, j) => panic!(
191 "RunWithInteractorResult::OutputLimitExceeded({},{}) is not allowed",
192 i, j
193 ),
194 }
195 }
196
197 pub fn is_ok(&self) -> bool {
198 match self {
199 RunWithInteractorResult::Ok(_, _) => true,
200 _ => false,
201 }
202 }
203}
204
205#[derive(Debug, Clone)]
206pub enum OnlyRunResult {
207 PermissionDenied,
208 SettingError,
209 CompileError(String),
210 InternalError(String),
211 RuntimeError(ProcessResource),
212 MemoryLimitExceeded(ProcessResource),
213 TimeLimitExceeded(ProcessResource),
214 OutputLimitExceeded(ProcessResource),
215 Ok(ProcessResource),
216}
217
218impl OnlyRunResult {
219 pub fn unwrap(self) -> ProcessResource {
220 match self {
221 OnlyRunResult::Ok(i) => i,
222 OnlyRunResult::PermissionDenied => {
223 panic!("OnlyRunResult::PermissionDenied is not allowed")
224 }
225 OnlyRunResult::SettingError => panic!("OnlyRunResult::SettingError is not allowed"),
226 OnlyRunResult::CompileError(i) => {
227 panic!("OnlyRunResult::CompileError({}) is not allowed", i)
228 }
229 OnlyRunResult::InternalError(i) => {
230 panic!("OnlyRunResult::InternalError({}) is not allowed", i)
231 }
232 OnlyRunResult::RuntimeError(i) => {
233 panic!("OnlyRunResult::RuntimeError({}) is not allowed", i)
234 }
235 OnlyRunResult::MemoryLimitExceeded(i) => {
236 panic!("OnlyRunResult::MemoryLimitExceeded({}) is not allowed", i)
237 }
238 OnlyRunResult::TimeLimitExceeded(i) => {
239 panic!("OnlyRunResult::TimeLimitExceeded({}) is not allowed", i)
240 }
241 OnlyRunResult::OutputLimitExceeded(i) => {
242 panic!("OnlyRunResult::OutputLimitExceeded({}) is not allowed", i)
243 }
244 }
245 }
246
247 pub fn is_ok(&self) -> bool {
248 match self {
249 OnlyRunResult::Ok(_) => true,
250 _ => false,
251 }
252 }
253}
254
255impl std::fmt::Display for OnlyRunResult {
256 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
257 match self {
258 OnlyRunResult::PermissionDenied => write!(f, "PermissionDenied"),
259 OnlyRunResult::SettingError => write!(f, "SettingError"),
260 OnlyRunResult::CompileError(i) => write!(f, "CompileError({})", i),
261 OnlyRunResult::InternalError(i) => write!(f, "InternalError({})", i),
262 OnlyRunResult::RuntimeError(i) => write!(f, "RuntimeError({})", i),
263 OnlyRunResult::MemoryLimitExceeded(i) => write!(f, "MemoryLimitExceeded({})", i),
264 OnlyRunResult::TimeLimitExceeded(i) => write!(f, "TimeLimitExceeded({})", i),
265 OnlyRunResult::Ok(i) => write!(f, "Ok({})", i),
266 OnlyRunResult::OutputLimitExceeded(i) => write!(f, "OutputLimitExceeded({})", i),
267 }
268 }
269}
270
271impl From<CompileResult> for OnlyRunResult {
272 fn from(i: CompileResult) -> Self {
273 match i {
274 CompileResult::SettingError => OnlyRunResult::SettingError,
275 CompileResult::InternalError(i) => OnlyRunResult::InternalError(i),
276 CompileResult::CompileError(i) => OnlyRunResult::CompileError(i),
277 CompileResult::Ok(_) => {
278 panic!("From<CompileResult> for OnlyRunResult: CompileResult::Ok(_) is not allowed")
279 }
280 }
281 }
282}
283
284impl From<InitExeResourceResult> for OnlyRunResult {
285 fn from(i: InitExeResourceResult) -> Self {
286 match i {
287 InitExeResourceResult::PermissionDenied => OnlyRunResult::PermissionDenied,
288 InitExeResourceResult::InternalError(i) => OnlyRunResult::InternalError(i),
289 InitExeResourceResult::Ok(_) => panic!("From<InitExeResourceResult> for OnlyRunResult: InitExeResourceResult::Ok(_) is not allowed"),
290 }
291 }
292}
293
294impl From<RunToEndResult> for OnlyRunResult {
295 fn from(i: RunToEndResult) -> Self {
296 match i {
297 RunToEndResult::InternalError(i) => OnlyRunResult::InternalError(i),
298 RunToEndResult::RuntimeError(i) => OnlyRunResult::RuntimeError(i),
299 RunToEndResult::MemoryLimitExceeded(i) => OnlyRunResult::MemoryLimitExceeded(i),
300 RunToEndResult::TimeLimitExceeded(i) => OnlyRunResult::TimeLimitExceeded(i),
301 RunToEndResult::Ok(i) => OnlyRunResult::Ok(i),
302 RunToEndResult::OutputLimitExceeded(i) => OnlyRunResult::OutputLimitExceeded(i),
303 }
304 }
305}
306
307#[derive(Debug, Clone)]
308pub enum RunAndEvalResult {
309 SettingError,
310 PermissionDenied,
311 InternalError(String),
312 CompileError(String),
313 RuntimeError(ProcessResource, ProcessResource),
314 MemoryLimitExceeded(ProcessResource, ProcessResource),
315 TimeLimitExceeded(ProcessResource, ProcessResource),
316 OutputLimitExceeded(ProcessResource, ProcessResource),
317 EvalCompileError(String),
318 EvalRuntimeError(ProcessResource, ProcessResource),
319 EvalMemoryLimitExceeded(ProcessResource, ProcessResource),
320 EvalTimeLimitExceeded(ProcessResource, ProcessResource),
321 EvalOutputLimitExceeded(ProcessResource, ProcessResource),
322 Ok(ProcessResource, ProcessResource),
323}
324
325impl RunAndEvalResult {
326 pub fn to_eval(&self) -> Self {
327 match self {
328 RunAndEvalResult::SettingError => RunAndEvalResult::SettingError,
329 RunAndEvalResult::InternalError(i) => RunAndEvalResult::InternalError(i.clone()),
330 RunAndEvalResult::CompileError(i) => RunAndEvalResult::EvalCompileError(i.clone()),
331 RunAndEvalResult::RuntimeError(i, j) => {
332 RunAndEvalResult::EvalRuntimeError(i.clone(), j.clone())
333 }
334 RunAndEvalResult::MemoryLimitExceeded(i, j) => {
335 RunAndEvalResult::EvalMemoryLimitExceeded(i.clone(), j.clone())
336 }
337 RunAndEvalResult::TimeLimitExceeded(i, j) => {
338 RunAndEvalResult::EvalTimeLimitExceeded(i.clone(), j.clone())
339 }
340 RunAndEvalResult::EvalCompileError(_) => {
341 panic!("RunAndEvalResult::EvalCompileError(_) is not allowed")
342 }
343 RunAndEvalResult::EvalRuntimeError(_, _) => {
344 panic!("RunAndEvalResult::EvalRuntimeError(_, _) is not allowed")
345 }
346 RunAndEvalResult::EvalMemoryLimitExceeded(_, _) => {
347 panic!("RunAndEvalResult::EvalMemoryLimitExceeded(_, _) is not allowed")
348 }
349 RunAndEvalResult::EvalTimeLimitExceeded(_, _) => {
350 panic!("RunAndEvalResult::EvalTimeLimitExceeded(_, _) is not allowed")
351 }
352 RunAndEvalResult::Ok(_, _) => panic!("RunAndEvalResult::Ok(_, _) is not allowed"),
353 RunAndEvalResult::PermissionDenied => RunAndEvalResult::PermissionDenied,
354 RunAndEvalResult::OutputLimitExceeded(i, j) => {
355 RunAndEvalResult::EvalOutputLimitExceeded(i.clone(), j.clone())
356 }
357 RunAndEvalResult::EvalOutputLimitExceeded(_, _) => {
358 panic!("RunAndEvalResult::EvalOutputLimitExceeded(_, _) is not allowed")
359 }
360 }
361 }
362
363 pub fn unwrap(self) -> (ProcessResource, ProcessResource) {
364 match self {
365 RunAndEvalResult::Ok(i, j) => (i, j),
366 RunAndEvalResult::SettingError => {
367 panic!("RunAndEvalResult::SettingError is not allowed")
368 }
369 RunAndEvalResult::PermissionDenied => {
370 panic!("RunAndEvalResult::PermissionDenied is not allowed")
371 }
372 RunAndEvalResult::InternalError(i) => {
373 panic!("RunAndEvalResult::InternalError({}) is not allowed", i)
374 }
375 RunAndEvalResult::CompileError(i) => {
376 panic!("RunAndEvalResult::CompileError({}) is not allowed", i)
377 }
378 RunAndEvalResult::RuntimeError(i, j) => {
379 panic!("RunAndEvalResult::RuntimeError({},{}) is not allowed", i, j)
380 }
381 RunAndEvalResult::MemoryLimitExceeded(i, j) => panic!(
382 "RunAndEvalResult::MemoryLimitExceeded({},{}) is not allowed",
383 i, j
384 ),
385 RunAndEvalResult::TimeLimitExceeded(i, j) => panic!(
386 "RunAndEvalResult::TimeLimitExceeded({},{}) is not allowed",
387 i, j
388 ),
389 RunAndEvalResult::EvalCompileError(i) => {
390 panic!("RunAndEvalResult::EvalCompileError({}) is not allowed", i)
391 }
392 RunAndEvalResult::EvalRuntimeError(i, j) => panic!(
393 "RunAndEvalResult::EvalRuntimeError({},{}) is not allowed",
394 i, j
395 ),
396 RunAndEvalResult::EvalMemoryLimitExceeded(i, j) => panic!(
397 "RunAndEvalResult::EvalMemoryLimitExceeded({},{}) is not allowed",
398 i, j
399 ),
400 RunAndEvalResult::EvalTimeLimitExceeded(i, j) => panic!(
401 "RunAndEvalResult::EvalTimeLimitExceeded({},{}) is not allowed",
402 i, j
403 ),
404 RunAndEvalResult::EvalOutputLimitExceeded(i, j) => panic!(
405 "RunAndEvalResult::EvalOutputLimitExceeded({},{}) is not allowed",
406 i, j
407 ),
408 RunAndEvalResult::OutputLimitExceeded(i, j) => panic!(
409 "RunAndEvalResult::OutputLimitExceeded({},{}) is not allowed",
410 i, j
411 ),
412 }
413 }
414
415 pub fn is_ok(&self) -> bool {
416 match self {
417 RunAndEvalResult::Ok(_, _) => true,
418 _ => false,
419 }
420 }
421}
422
423impl std::fmt::Display for RunAndEvalResult {
424 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
425 match self {
426 RunAndEvalResult::SettingError => write!(f, "SettingError"),
427 RunAndEvalResult::InternalError(i) => write!(f, "InternalError({})", i),
428 RunAndEvalResult::CompileError(i) => write!(f, "CompileError({})", i),
429 RunAndEvalResult::RuntimeError(i, j) => write!(f, "RuntimeError({},{})", i, j),
430 RunAndEvalResult::MemoryLimitExceeded(i, j) => {
431 write!(f, "MemoryLimitExceeded({},{})", i, j)
432 }
433 RunAndEvalResult::TimeLimitExceeded(i, j) => {
434 write!(f, "TimeLimitExceeded({},{})", i, j)
435 }
436 RunAndEvalResult::EvalCompileError(i) => write!(f, "EvalCompileError({})", i),
437 RunAndEvalResult::EvalRuntimeError(i, j) => write!(f, "EvalRuntimeError({},{})", i, j),
438 RunAndEvalResult::EvalMemoryLimitExceeded(i, j) => {
439 write!(f, "EvalMemoryLimitExceeded({},{})", i, j)
440 }
441 RunAndEvalResult::EvalTimeLimitExceeded(i, j) => {
442 write!(f, "EvalTimeLimitExceeded({},{})", i, j)
443 }
444 RunAndEvalResult::Ok(i, j) => write!(f, "Ok({}, {})", i, j),
445 RunAndEvalResult::PermissionDenied => write!(f, "PermissionDenied"),
446 RunAndEvalResult::OutputLimitExceeded(i, j) => {
447 write!(f, "OutputLimitExceeded({},{})", i, j)
448 }
449 RunAndEvalResult::EvalOutputLimitExceeded(i, j) => {
450 write!(f, "EvalOutputLimitExceeded({},{})", i, j)
451 }
452 }
453 }
454}
455
456impl From<CompileResult> for RunAndEvalResult {
457 fn from(i: CompileResult) -> Self {
458 match i {
459 CompileResult::SettingError => RunAndEvalResult::SettingError,
460 CompileResult::InternalError(i) => RunAndEvalResult::InternalError(i),
461 CompileResult::CompileError(i) => RunAndEvalResult::CompileError(i),
462 CompileResult::Ok(_) => panic!(
463 "From<CompileResult> for RunAndEvalResult: CompileResult::Ok(_) is not allowed"
464 ),
465 }
466 }
467}
468
469impl From<InitExeResourceResult> for RunAndEvalResult {
470 fn from(i: InitExeResourceResult) -> Self {
471 match i {
472 InitExeResourceResult::PermissionDenied => RunAndEvalResult::PermissionDenied,
473 InitExeResourceResult::InternalError(i) => RunAndEvalResult::InternalError(i),
474 InitExeResourceResult::Ok(_) => panic!("From<InitExeResourceResult> for RunAndEvalResult: InitExeResourceResult::Ok(_) is not allowed"),
475 }
476 }
477}
478
479#[derive(Debug, Clone)]
480pub enum AnsAndEvalResult {
481 PermissionDenied,
482 SettingError,
483 InternalError(String),
484 EvalCompileError(String),
485 EvalRuntimeError(ProcessResource),
486 EvalMemoryLimitExceeded(ProcessResource),
487 EvalTimeLimitExceeded(ProcessResource),
488 EvalOutputLimitExceeded(ProcessResource),
489 Ok(ProcessResource),
490}
491
492impl AnsAndEvalResult {
493 pub fn unwrap(self) -> ProcessResource {
494 match self {
495 AnsAndEvalResult::Ok(i) => i,
496 AnsAndEvalResult::PermissionDenied => {
497 panic!("AnsAndEvalResult::PermissionDenied is not allowed")
498 }
499 AnsAndEvalResult::SettingError => {
500 panic!("AnsAndEvalResult::SettingError is not allowed")
501 }
502 AnsAndEvalResult::InternalError(i) => {
503 panic!("AnsAndEvalResult::InternalError({}) is not allowed", i)
504 }
505 AnsAndEvalResult::EvalCompileError(i) => {
506 panic!("AnsAndEvalResult::EvalCompileError({}) is not allowed", i)
507 }
508 AnsAndEvalResult::EvalRuntimeError(i) => {
509 panic!("AnsAndEvalResult::EvalRuntimeError({}) is not allowed", i)
510 }
511 AnsAndEvalResult::EvalMemoryLimitExceeded(i) => panic!(
512 "AnsAndEvalResult::EvalMemoryLimitExceeded({}) is not allowed",
513 i
514 ),
515 AnsAndEvalResult::EvalTimeLimitExceeded(i) => panic!(
516 "AnsAndEvalResult::EvalTimeLimitExceeded({}) is not allowed",
517 i
518 ),
519 AnsAndEvalResult::EvalOutputLimitExceeded(i) => panic!(
520 "AnsAndEvalResult::EvalOutputLimitExceeded({}) is not allowed",
521 i
522 ),
523 }
524 }
525
526 pub fn is_ok(&self) -> bool {
527 match self {
528 AnsAndEvalResult::Ok(_) => true,
529 _ => false,
530 }
531 }
532}
533
534impl std::fmt::Display for AnsAndEvalResult {
535 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
536 match self {
537 AnsAndEvalResult::PermissionDenied => write!(f, "PermissionDenied"),
538 AnsAndEvalResult::SettingError => write!(f, "SettingError"),
539 AnsAndEvalResult::InternalError(i) => write!(f, "InternalError({})", i),
540 AnsAndEvalResult::EvalCompileError(i) => write!(f, "EvalCompileError({})", i),
541 AnsAndEvalResult::EvalRuntimeError(i) => write!(f, "EvalRuntimeError({})", i),
542 AnsAndEvalResult::EvalMemoryLimitExceeded(i) => {
543 write!(f, "EvalMemoryLimitExceeded({})", i)
544 }
545 AnsAndEvalResult::EvalTimeLimitExceeded(i) => write!(f, "EvalTimeLimitExceeded({})", i),
546 AnsAndEvalResult::Ok(i) => write!(f, "Ok({})", i),
547 AnsAndEvalResult::EvalOutputLimitExceeded(i) => {
548 write!(f, "EvalOutputLimitExceeded({})", i)
549 }
550 }
551 }
552}
553
554impl From<CompileResult> for AnsAndEvalResult {
555 fn from(i: CompileResult) -> Self {
556 match i {
557 CompileResult::SettingError => AnsAndEvalResult::SettingError,
558 CompileResult::InternalError(i) => AnsAndEvalResult::InternalError(i),
559 CompileResult::CompileError(i) => AnsAndEvalResult::EvalCompileError(i),
560 CompileResult::Ok(_) => panic!(
561 "From<CompileResult> for AnsAndEvalResult: CompileResult::Ok(_) is not allowed"
562 ),
563 }
564 }
565}
566
567impl From<InitExeResourceResult> for AnsAndEvalResult {
568 fn from(i: InitExeResourceResult) -> Self {
569 match i {
570 InitExeResourceResult::PermissionDenied => AnsAndEvalResult::PermissionDenied,
571 InitExeResourceResult::InternalError(i) => AnsAndEvalResult::InternalError(i),
572 InitExeResourceResult::Ok(_) => panic!("From<InitExeResourceResult> for AnsAndEvalResult: InitExeResourceResult::Ok(_) is not allowed"),
573 }
574 }
575}
576
577impl From<RunToEndResult> for AnsAndEvalResult {
578 fn from(i: RunToEndResult) -> Self {
579 match i {
580 RunToEndResult::InternalError(i) => AnsAndEvalResult::InternalError(i),
581 RunToEndResult::RuntimeError(i) => AnsAndEvalResult::EvalRuntimeError(i),
582 RunToEndResult::MemoryLimitExceeded(i) => AnsAndEvalResult::EvalMemoryLimitExceeded(i),
583 RunToEndResult::TimeLimitExceeded(i) => AnsAndEvalResult::EvalTimeLimitExceeded(i),
584 RunToEndResult::Ok(i) => AnsAndEvalResult::Ok(i),
585 RunToEndResult::OutputLimitExceeded(i) => AnsAndEvalResult::EvalOutputLimitExceeded(i),
586 }
587 }
588}
589
590#[derive(Debug, Clone)]
591pub enum RunAndInteractResult {
592 PermissionDenied,
593 SettingError,
594 InternalError(String),
595 CompileError(String),
596 RuntimeError(ProcessResource, ProcessResource),
597 MemoryLimitExceeded(ProcessResource, ProcessResource),
598 TimeLimitExceeded(ProcessResource, ProcessResource),
599 OutputLimitExceeded(ProcessResource, ProcessResource),
600 InteractorCompileError(String),
601 InteractorRuntimeError(ProcessResource, ProcessResource),
602 InteractorMemoryLimitExceeded(ProcessResource, ProcessResource),
603 InteractorTimeLimitExceeded(ProcessResource, ProcessResource),
604 InteractorOutputLimitExceeded(ProcessResource, ProcessResource),
605 Ok(ProcessResource, ProcessResource),
606}
607
608impl RunAndInteractResult {
609 pub fn to_interactor(&self) -> Self {
610 match self {
611 RunAndInteractResult::SettingError => RunAndInteractResult::SettingError,
612 RunAndInteractResult::InternalError(i) => {
613 RunAndInteractResult::InternalError(i.clone())
614 }
615 RunAndInteractResult::CompileError(i) => {
616 RunAndInteractResult::InteractorCompileError(i.clone())
617 }
618 RunAndInteractResult::RuntimeError(i, j) => {
619 RunAndInteractResult::InteractorRuntimeError(i.clone(), j.clone())
620 }
621 RunAndInteractResult::MemoryLimitExceeded(i, j) => {
622 RunAndInteractResult::InteractorMemoryLimitExceeded(i.clone(), j.clone())
623 }
624 RunAndInteractResult::TimeLimitExceeded(i, j) => {
625 RunAndInteractResult::InteractorTimeLimitExceeded(i.clone(), j.clone())
626 }
627 RunAndInteractResult::InteractorCompileError(_) => {
628 panic!("RunAndInteractResult::InteractorCompileError(_) is not allowed")
629 }
630 RunAndInteractResult::InteractorRuntimeError(_, _) => {
631 panic!("RunAndInteractResult::InteractorRuntimeError(_, _) is not allowed")
632 }
633 RunAndInteractResult::InteractorMemoryLimitExceeded(_, _) => {
634 panic!("RunAndInteractResult::InteractorMemoryLimitExceeded(_, _) is not allowed")
635 }
636 RunAndInteractResult::InteractorTimeLimitExceeded(_, _) => {
637 panic!("RunAndInteractResult::InteractorTimeLimitExceeded(_, _) is not allowed")
638 }
639 RunAndInteractResult::Ok(_, _) => {
640 panic!("RunAndInteractResult::Ok(_, _) is not allowed")
641 }
642 RunAndInteractResult::PermissionDenied => RunAndInteractResult::PermissionDenied,
643 RunAndInteractResult::OutputLimitExceeded(i, j) => {
644 RunAndInteractResult::InteractorOutputLimitExceeded(i.clone(), j.clone())
645 }
646 RunAndInteractResult::InteractorOutputLimitExceeded(_, _) => {
647 panic!("RunAndInteractResult::InteractorOutputLimitExceeded(_, _) is not allowed")
648 }
649 }
650 }
651
652 pub fn unwrap(self) -> (ProcessResource, ProcessResource) {
653 match self {
654 RunAndInteractResult::Ok(i, j) => (i, j),
655 RunAndInteractResult::SettingError => {
656 panic!("RunAndInteractResult::SettingError is not allowed")
657 }
658 RunAndInteractResult::PermissionDenied => {
659 panic!("RunAndInteractResult::PermissionDenied is not allowed")
660 }
661 RunAndInteractResult::InternalError(i) => {
662 panic!("RunAndInteractResult::InternalError({}) is not allowed", i)
663 }
664 RunAndInteractResult::CompileError(i) => {
665 panic!("RunAndInteractResult::CompileError({}) is not allowed", i)
666 }
667 RunAndInteractResult::RuntimeError(i, j) => panic!(
668 "RunAndInteractResult::RuntimeError({},{}) is not allowed",
669 i, j
670 ),
671 RunAndInteractResult::MemoryLimitExceeded(i, j) => panic!(
672 "RunAndInteractResult::MemoryLimitExceeded({},{}) is not allowed",
673 i, j
674 ),
675 RunAndInteractResult::TimeLimitExceeded(i, j) => panic!(
676 "RunAndInteractResult::TimeLimitExceeded({},{}) is not allowed",
677 i, j
678 ),
679 RunAndInteractResult::InteractorCompileError(i) => panic!(
680 "RunAndInteractResult::InteractorCompileError({}) is not allowed",
681 i
682 ),
683 RunAndInteractResult::InteractorRuntimeError(i, j) => panic!(
684 "RunAndInteractResult::InteractorRuntimeError({},{}) is not allowed",
685 i, j
686 ),
687 RunAndInteractResult::InteractorMemoryLimitExceeded(i, j) => panic!(
688 "RunAndInteractResult::InteractorMemoryLimitExceeded({},{}) is not allowed",
689 i, j
690 ),
691 RunAndInteractResult::InteractorTimeLimitExceeded(i, j) => panic!(
692 "RunAndInteractResult::InteractorTimeLimitExceeded({},{}) is not allowed",
693 i, j
694 ),
695 RunAndInteractResult::InteractorOutputLimitExceeded(i, j) => panic!(
696 "RunAndInteractResult::InteractorOutputLimitExceeded({},{}) is not allowed",
697 i, j
698 ),
699 RunAndInteractResult::OutputLimitExceeded(i, j) => panic!(
700 "RunAndInteractResult::OutputLimitExceeded({},{}) is not allowed",
701 i, j
702 ),
703 }
704 }
705
706 pub fn is_ok(&self) -> bool {
707 match self {
708 RunAndInteractResult::Ok(_, _) => true,
709 _ => false,
710 }
711 }
712}
713
714impl std::fmt::Display for RunAndInteractResult {
715 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
716 match self {
717 RunAndInteractResult::SettingError => write!(f, "SettingError"),
718 RunAndInteractResult::InternalError(i) => write!(f, "InternalError({})", i),
719 RunAndInteractResult::CompileError(i) => write!(f, "CompileError({})", i),
720 RunAndInteractResult::RuntimeError(i, j) => write!(f, "RuntimeError({},{})", i, j),
721 RunAndInteractResult::MemoryLimitExceeded(i, j) => {
722 write!(f, "MemoryLimitExceeded({},{})", i, j)
723 }
724 RunAndInteractResult::TimeLimitExceeded(i, j) => {
725 write!(f, "TimeLimitExceeded({},{})", i, j)
726 }
727 RunAndInteractResult::InteractorCompileError(i) => {
728 write!(f, "InteractorCompileError({})", i)
729 }
730 RunAndInteractResult::InteractorRuntimeError(i, j) => {
731 write!(f, "InteractorRuntimeError({},{})", i, j)
732 }
733 RunAndInteractResult::InteractorMemoryLimitExceeded(i, j) => {
734 write!(f, "InteractorMemoryLimitExceeded({},{})", i, j)
735 }
736 RunAndInteractResult::InteractorTimeLimitExceeded(i, j) => {
737 write!(f, "InteractorTimeLimitExceeded({},{})", i, j)
738 }
739 RunAndInteractResult::Ok(i, j) => write!(f, "Ok({}, {})", i, j),
740 RunAndInteractResult::PermissionDenied => write!(f, "PermissionDenied"),
741 RunAndInteractResult::InteractorOutputLimitExceeded(i, j) => {
742 write!(f, "InteractorOutputLimitExceeded({},{})", i, j)
743 }
744 RunAndInteractResult::OutputLimitExceeded(i, j) => {
745 write!(f, "OutputLimitExceeded({},{})", i, j)
746 }
747 }
748 }
749}
750
751impl From<CompileResult> for RunAndInteractResult {
752 fn from(i: CompileResult) -> Self {
753 match i {
754 CompileResult::SettingError => RunAndInteractResult::SettingError,
755 CompileResult::InternalError(i) => RunAndInteractResult::InternalError(i),
756 CompileResult::CompileError(i) => RunAndInteractResult::CompileError(i),
757 CompileResult::Ok(_) => panic!(
758 "From<CompileResult> for RunAndInteractResult: CompileResult::Ok(_) is not allowed"
759 ),
760 }
761 }
762}
763
764impl From<InitExeResourceResult> for RunAndInteractResult {
765 fn from(i: InitExeResourceResult) -> Self {
766 match i {
767 InitExeResourceResult::PermissionDenied => RunAndInteractResult::PermissionDenied,
768 InitExeResourceResult::InternalError(i) => RunAndInteractResult::InternalError(i),
769 InitExeResourceResult::Ok(_) => panic!("From<InitExeResourceResult> for RunAndInteractResult: InitExeResourceResult::Ok(_) is not allowed"),
770 }
771 }
772}
773
774impl From<RunWithInteractorResult> for RunAndInteractResult {
775 fn from(i: RunWithInteractorResult) -> Self {
776 match i {
777 RunWithInteractorResult::InternalError(i) => RunAndInteractResult::InternalError(i),
778 RunWithInteractorResult::RuntimeError(i, j) => RunAndInteractResult::RuntimeError(i, j),
779 RunWithInteractorResult::MemoryLimitExceeded(i, j) => {
780 RunAndInteractResult::MemoryLimitExceeded(i, j)
781 }
782 RunWithInteractorResult::TimeLimitExceeded(i, j) => {
783 RunAndInteractResult::TimeLimitExceeded(i, j)
784 }
785 RunWithInteractorResult::InteractorRuntimeError(i, j) => {
786 RunAndInteractResult::InteractorRuntimeError(i, j)
787 }
788 RunWithInteractorResult::InteractorMemoryLimitExceeded(i, j) => {
789 RunAndInteractResult::InteractorMemoryLimitExceeded(i, j)
790 }
791 RunWithInteractorResult::InteractorTimeLimitExceeded(i, j) => {
792 RunAndInteractResult::InteractorTimeLimitExceeded(i, j)
793 }
794 RunWithInteractorResult::Ok(i, j) => RunAndInteractResult::Ok(i, j),
795 RunWithInteractorResult::InteractorOutputLimitExceeded(i, j) => {
796 RunAndInteractResult::InteractorOutputLimitExceeded(i, j)
797 }
798 RunWithInteractorResult::OutputLimitExceeded(i, j) => {
799 RunAndInteractResult::OutputLimitExceeded(i, j)
800 }
801 }
802 }
803}