1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
use std::error;
use std::error::Error;
use std::fmt;
use std::io;
use std::sync::MutexGuard;
use std::sync::PoisonError;
use std::num::ParseIntError;
use crossbeam_channel::SendError;
use crossbeam_channel::RecvError;
use command::UsiCommand;
use selfmatch::SelfMatchMessage;
#[derive(Debug)]
pub enum EventDispatchError<'a,T,K,E>
where T: fmt::Debug + 'a, K: fmt::Debug, E: Error + fmt::Debug + 'static {
ErrorFromHandler(EventHandlerError<K,E>),
MutexLockFailedError(PoisonError<MutexGuard<'a,T>>),
ContainError,
}
#[derive(Debug)]
pub enum EventHandlerError<K,E> where K: fmt::Debug, E: Error + fmt::Debug + 'static {
Fail(String),
InvalidState(K),
PlayerError(E),
}
impl<K,E> fmt::Display for EventHandlerError<K,E> where K: fmt::Debug, E: Error + fmt::Debug {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
EventHandlerError::Fail(ref s) => write!(f,"An error occurred while executing the event handler. ({})",s),
EventHandlerError::InvalidState(ref e) => write!(f,
"The type of event passed and the event being processed do not match. (Event kind = {:?})", e),
EventHandlerError::PlayerError(_) => write!(f,"An error occurred while processing the player object in the event handler."),
}
}
}
impl<K,E> error::Error for EventHandlerError<K,E> where K: fmt::Debug, E: Error + fmt::Debug {
fn description(&self) -> &str {
match *self {
EventHandlerError::Fail(_) => "An error occurred while executing the event handler.",
EventHandlerError::InvalidState(_) => "The type of event passed and the event being processed do not match.",
EventHandlerError::PlayerError(_) => "An error occurred while processing the player object in the event handler.",
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
EventHandlerError::Fail(_) => None,
EventHandlerError::InvalidState(_) => None,
EventHandlerError::PlayerError(ref e) => Some(e),
}
}
}
impl<'a,T,K,E> fmt::Display for EventDispatchError<'a,T,K,E>
where T: fmt::Debug, K: fmt::Debug, E: Error + fmt::Debug {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
EventDispatchError::ErrorFromHandler(_) => write!(f, "An error occurred while processing an event."),
EventDispatchError::MutexLockFailedError(_) => write!(f, "Could not get exclusive lock on object."),
EventDispatchError::ContainError => write!(f, "One or more errors occurred while executing the event handler."),
}
}
}
impl<'a,T,K,E> error::Error for EventDispatchError<'a,T,K,E>
where T: fmt::Debug, K: fmt::Debug + 'static, E: Error + fmt::Debug {
fn description(&self) -> &str {
match *self {
EventDispatchError::ErrorFromHandler(_) => "An error occurred while processing an event.",
EventDispatchError::MutexLockFailedError(_) => "Could not get exclusive lock on object.",
EventDispatchError::ContainError => "Error executing event handler",
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
EventDispatchError::ErrorFromHandler(ref e) => Some(e),
EventDispatchError::MutexLockFailedError(_) => None,
EventDispatchError::ContainError => None,
}
}
}
impl<'a,T,K,E> From<PoisonError<MutexGuard<'a,T>>> for EventDispatchError<'a,T,K,E>
where T: fmt::Debug + 'a, K: fmt::Debug, E: Error + fmt::Debug {
fn from(err: PoisonError<MutexGuard<'a,T>>) -> EventDispatchError<'a,T,K,E> {
EventDispatchError::MutexLockFailedError(err)
}
}
impl<'a,T,K,E> From<EventHandlerError<K,E>> for EventDispatchError<'a,T,K,E>
where T: fmt::Debug, K: fmt::Debug, E: Error + fmt::Debug {
fn from(err: EventHandlerError<K,E>) -> EventDispatchError<'a,T,K,E> {
EventDispatchError::ErrorFromHandler(err)
}
}
#[derive(Debug,Eq,PartialEq)]
pub struct InvalidStateError(pub String);
impl fmt::Display for InvalidStateError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
InvalidStateError(ref s) => write!(f, "{}",s)
}
}
}
impl error::Error for InvalidStateError {
fn description(&self) -> &str {
match *self {
InvalidStateError(_) => "invalid state."
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
InvalidStateError(_) => None
}
}
}
#[derive(Debug,Eq,PartialEq)]
pub struct DanConvertError(pub u32);
impl fmt::Display for DanConvertError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
DanConvertError(n) => write!(f, "The 'dan' value {} is outside the range of valid values.",n)
}
}
}
impl error::Error for DanConvertError {
fn description(&self) -> &str {
match *self {
DanConvertError(_) => "The value of the 'dan' is out of the range of valid values"
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
DanConvertError(_) => None
}
}
}
#[derive(Debug,Eq,PartialEq)]
pub enum ToMoveStringConvertError {
CharConvert(DanConvertError),
AbortedError,
}
impl fmt::Display for ToMoveStringConvertError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ToMoveStringConvertError::CharConvert(_) => {
write!(f, "Conversion of move to string representation failed.")
},
ToMoveStringConvertError::AbortedError => {
write!(f,"The command string can not be generated because the operation was interrupted.")
}
}
}
}
impl error::Error for ToMoveStringConvertError {
fn description(&self) -> &str {
match *self {
ToMoveStringConvertError::CharConvert(_) => {
"Conversion of move to string representation failed."
},
ToMoveStringConvertError::AbortedError => {
"The command string can not be generated because the operation was interrupted."
}
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
ToMoveStringConvertError::CharConvert(ref e) => Some(e),
ToMoveStringConvertError::AbortedError => None,
}
}
}
impl From<DanConvertError> for ToMoveStringConvertError {
fn from(err: DanConvertError) -> ToMoveStringConvertError {
ToMoveStringConvertError::CharConvert(err)
}
}
#[derive(Debug,Eq,PartialEq)]
pub enum UsiOutputCreateError {
ValidationError(UsiCommand),
InvalidStateError(String),
InvalidInfoCommand(String),
ConvertError(ToMoveStringConvertError),
AbortedError,
}
impl fmt::Display for UsiOutputCreateError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
UsiOutputCreateError::ConvertError(_) => write!(f, "Failed to generate command string output to USI protocol."),
UsiOutputCreateError::InvalidStateError(ref s) => write!(f, "The state of {} is invalid.", s),
UsiOutputCreateError::InvalidInfoCommand(ref s) => write!(f, "The content of the info command is invalid. ({})", s),
UsiOutputCreateError::ValidationError(ref cmd) => {
match *cmd {
UsiCommand::UsiBestMove(_) => write!(f, "The state of the object that generated the bestmove command is invalid."),
UsiCommand::UsiInfo(_) => write!(f, "The state of the object that generated the info command is invalid."),
UsiCommand::UsiCheckMate(_) => write!(f, "The state of the object that generated the checkmate command is invalid."),
_ => write!(f,"An unexpected exception occurred in command validation."),
}
},
UsiOutputCreateError::AbortedError => write!(f,"The command string can not be generated because the operation was interrupted."),
}
}
}
impl error::Error for UsiOutputCreateError {
fn description(&self) -> &str {
match *self {
UsiOutputCreateError::ConvertError(_) => "Failed to generate command string output to USI protocol.",
UsiOutputCreateError::InvalidStateError(_) => "The state of the command generation object is invalid",
UsiOutputCreateError::InvalidInfoCommand(_) => "The content of the info command is invalid.",
UsiOutputCreateError::ValidationError(ref cmd) => {
match *cmd {
UsiCommand::UsiBestMove(_) => "The state of the object that generated the bestmove command is invalid",
UsiCommand::UsiInfo(_) => "The state of the object that generated the info command is invalid",
UsiCommand::UsiCheckMate(_) => "The state of the object that generated the checkmate command is invalid",
_ => "An unexpected exception occurred in command validation",
}
},
UsiOutputCreateError::AbortedError => "The command string can not be generated because the operation was interrupted.",
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
UsiOutputCreateError::ConvertError(ref e) => Some(e),
UsiOutputCreateError::InvalidStateError(_) => None,
UsiOutputCreateError::InvalidInfoCommand(_)=> None,
UsiOutputCreateError::ValidationError(_) => None,
UsiOutputCreateError::AbortedError => None,
}
}
}
impl From<ToMoveStringConvertError> for UsiOutputCreateError {
fn from(err: ToMoveStringConvertError) -> UsiOutputCreateError {
UsiOutputCreateError::ConvertError(err)
}
}
impl<T,E> From<UsiOutputCreateError> for EventHandlerError<T,E> where T: fmt::Debug, E: Error + fmt::Debug {
fn from(err: UsiOutputCreateError) -> EventHandlerError<T,E> {
EventHandlerError::Fail(err.to_string())
}
}
impl<T,E> From<E> for EventHandlerError<T,E> where T: fmt::Debug, E: PlayerError {
fn from(err: E) -> EventHandlerError<T,E> {
EventHandlerError::PlayerError(err)
}
}
#[derive(Debug,Eq,PartialEq)]
pub enum InfoSendError {
Fail(String)
}
impl fmt::Display for InfoSendError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
InfoSendError::Fail(ref s) => write!(f,"An error occurred when sending the info command. ({})",s),
}
}
}
impl error::Error for InfoSendError {
fn description(&self) -> &str {
match *self {
InfoSendError::Fail(_) => "An error occurred when sending the info command.",
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
InfoSendError::Fail(_) => None,
}
}
}
impl From<UsiOutputCreateError> for InfoSendError {
fn from(e: UsiOutputCreateError) -> InfoSendError {
InfoSendError::Fail(format!("{}",e))
}
}
#[derive(Debug,Eq,PartialEq)]
pub enum TypeConvertError<T> where T: fmt::Debug + fmt::Display {
SyntaxError(T),
LogicError(T),
}
impl<T> fmt::Display for TypeConvertError<T> where T: fmt::Debug + fmt::Display {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
TypeConvertError::SyntaxError(ref e) => write!(f, "An error occurred in type conversion. from = ({:?})",e),
TypeConvertError::LogicError(ref e) => write!(f, "An error occurred in type conversion (logic error, {})",e),
}
}
}
impl<T> error::Error for TypeConvertError<T> where T: fmt::Debug + fmt::Display {
fn description(&self) -> &str {
match *self {
TypeConvertError::SyntaxError(_) => "An error occurred in type conversion",
TypeConvertError::LogicError(_) => "An error occurred in type conversion (logic error)",
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
TypeConvertError::SyntaxError(_) => None,
TypeConvertError::LogicError(_) => None,
}
}
}
impl From<ParseIntError> for TypeConvertError<String> where String: fmt::Debug {
fn from(_: ParseIntError) -> TypeConvertError<String> {
TypeConvertError::SyntaxError(String::from("Failed parse string to integer."))
}
}
#[derive(Debug)]
pub enum USIAgentStartupError<E> where E: PlayerError {
MutexLockFailedOtherError(String),
IOError(String),
PlayerError(E),
}
impl<E> fmt::Display for USIAgentStartupError<E> where E: PlayerError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
USIAgentStartupError::MutexLockFailedOtherError(ref s) => write!(f, "Could not get exclusive lock on object. ({})",s),
USIAgentStartupError::IOError(ref s) => write!(f, "IO Error. ({})",s),
USIAgentStartupError::PlayerError(_) => write!(f,"An error occurred in the processing within the player object."),
}
}
}
impl<E> error::Error for USIAgentStartupError<E> where E: PlayerError {
fn description(&self) -> &str {
match *self {
USIAgentStartupError::MutexLockFailedOtherError(_) => "Could not get exclusive lock on object.",
USIAgentStartupError::IOError(_) => "IO Error.",
USIAgentStartupError::PlayerError(_) => "An error occurred in the processing within the player object.",
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
USIAgentStartupError::MutexLockFailedOtherError(_) => None,
USIAgentStartupError::IOError(_) => None,
USIAgentStartupError::PlayerError(ref e) => Some(e),
}
}
}
#[derive(Debug)]
pub enum USIAgentRunningError<'a,T,E> where T: fmt::Debug + 'a, E: PlayerError {
MutexLockFailedError(PoisonError<MutexGuard<'a,T>>),
StartupError(USIAgentStartupError<E>),
}
impl<'a,T,E> fmt::Display for USIAgentRunningError<'a,T,E> where T: fmt::Debug, E: PlayerError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
USIAgentRunningError::MutexLockFailedError(_) => write!(f, "Could not get exclusive lock on object."),
USIAgentRunningError::StartupError(_) => write!(f,"An error occurred during startup."),
}
}
}
impl<'a,T,E> error::Error for USIAgentRunningError<'a,T,E> where T: fmt::Debug, E: PlayerError {
fn description(&self) -> &str {
match *self {
USIAgentRunningError::MutexLockFailedError(_) => "Could not get exclusive lock on object.",
USIAgentRunningError::StartupError(_) => "An error occurred during the startup process of USIAgent.",
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
USIAgentRunningError::MutexLockFailedError(_) => None,
USIAgentRunningError::StartupError(ref e) => Some(e),
}
}
}
impl<'a,T,E> From<PoisonError<MutexGuard<'a,T>>> for USIAgentRunningError<'a,T,E>
where T: fmt::Debug + 'a, E: PlayerError {
fn from(err: PoisonError<MutexGuard<'a,T>>) -> USIAgentRunningError<'a,T,E> {
USIAgentRunningError::MutexLockFailedError(err)
}
}
impl<'a,T,E> From<USIAgentStartupError<E>> for USIAgentRunningError<'a,T,E>
where T: fmt::Debug + 'a, E: PlayerError {
fn from(err: USIAgentStartupError<E>) -> USIAgentRunningError<'a,T,E> {
USIAgentRunningError::StartupError(err)
}
}
#[derive(Debug,Eq,PartialEq)]
pub enum ShogiError {
InvalidState(String),
}
impl fmt::Display for ShogiError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ShogiError::InvalidState(ref s) => write!(f,"{}",s)
}
}
}
impl error::Error for ShogiError {
fn description(&self) -> &str {
match *self {
ShogiError::InvalidState(_) => "invalid state.",
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
ShogiError::InvalidState(_) => None,
}
}
}
#[derive(Debug,Eq,PartialEq)]
pub enum UsiProtocolError {
InvalidState(String),
}
impl fmt::Display for UsiProtocolError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
UsiProtocolError::InvalidState(ref s) => write!(f,"invalid state.(protocol was not processed proper, {})",s)
}
}
}
impl error::Error for UsiProtocolError {
fn description(&self) -> &str {
match *self {
UsiProtocolError::InvalidState(_) => "invalid state.(protocol was not processed proper)",
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
UsiProtocolError::InvalidState(_) => None,
}
}
}
#[derive(Debug)]
pub enum SelfMatchRunningError<E> where E: PlayerError {
InvalidState(String),
PlayerError(E),
PlayerThreadError(usize),
IOError(io::Error),
KifuWriteError(KifuWriteError),
RecvError(RecvError),
SendError(SendError<SelfMatchMessage>),
ThreadJoinFailed(String),
Fail(String),
}
impl<E> fmt::Display for SelfMatchRunningError<E> where E: PlayerError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
SelfMatchRunningError::InvalidState(ref s) => write!(f,"invalid state. ({})",s),
SelfMatchRunningError::PlayerError(_) => write!(f,"An error occurred in player thread."),
SelfMatchRunningError::PlayerThreadError(n) => write!(f,"An error occurred in player {}'s thread.",n),
SelfMatchRunningError::IOError(_) => write!(f,"IO Error."),
SelfMatchRunningError::KifuWriteError(_) => write!(f,"An error occurred when recording kifu.s"),
SelfMatchRunningError::RecvError(_) => write!(f,"An error occurred when receiving the message."),
SelfMatchRunningError::SendError(_) => write!(f,"An error occurred when sending the message."),
SelfMatchRunningError::ThreadJoinFailed(ref s) => write!(f,"An panic occurred in child thread. ({})",s),
SelfMatchRunningError::Fail(ref s) => write!(f,"An error occurred while running the self-match. ({})",s),
}
}
}
impl<E> error::Error for SelfMatchRunningError<E> where E: PlayerError {
fn description(&self) -> &str {
match *self {
SelfMatchRunningError::InvalidState(_) => "invalid state.",
SelfMatchRunningError::PlayerError(_) => "An error occurred in player thread.",
SelfMatchRunningError::PlayerThreadError(_) => "An error occurred in player thread.",
SelfMatchRunningError::IOError(_) => "IO Error.",
SelfMatchRunningError::KifuWriteError(_) => "There was an error writing kifu.",
SelfMatchRunningError::RecvError(_) => "An error occurred when receiving the message.",
SelfMatchRunningError::SendError(_) => "An error occurred while sending the message.",
SelfMatchRunningError::ThreadJoinFailed(_) => "An panic occurred in child thread.",
SelfMatchRunningError::Fail(_) => "An error occurred while running the self-match.",
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
SelfMatchRunningError::InvalidState(_) => None,
SelfMatchRunningError::PlayerError(ref e) => Some(e),
SelfMatchRunningError::PlayerThreadError(_) => None,
SelfMatchRunningError::IOError(ref e) => Some(e),
SelfMatchRunningError::KifuWriteError(ref e) => Some(e),
SelfMatchRunningError::RecvError(ref e) => Some(e),
SelfMatchRunningError::SendError(ref e) => Some(e),
SelfMatchRunningError::ThreadJoinFailed(_) => None,
SelfMatchRunningError::Fail(_) => None,
}
}
}
impl<E> From<TypeConvertError<String>> for SelfMatchRunningError<E> where String: fmt::Debug, E: PlayerError {
fn from(_: TypeConvertError<String>) -> SelfMatchRunningError<E> {
SelfMatchRunningError::Fail(String::from("An error occurred during type conversion from Move to Moved."))
}
}
impl<E> From<RecvError> for SelfMatchRunningError<E> where E: PlayerError {
fn from(err: RecvError) -> SelfMatchRunningError<E> {
SelfMatchRunningError::RecvError(err)
}
}
impl<E> From<SendError<SelfMatchMessage>> for SelfMatchRunningError<E> where E: PlayerError {
fn from(err: SendError<SelfMatchMessage>) -> SelfMatchRunningError<E> {
SelfMatchRunningError::SendError(err)
}
}
impl<E> From<io::Error> for SelfMatchRunningError<E> where E: PlayerError {
fn from(err: io::Error) -> SelfMatchRunningError<E> {
SelfMatchRunningError::IOError(err)
}
}
impl<E> From<KifuWriteError> for SelfMatchRunningError<E> where E: PlayerError {
fn from(err: KifuWriteError) -> SelfMatchRunningError<E> {
SelfMatchRunningError::KifuWriteError(err)
}
}
impl<E> From<E> for SelfMatchRunningError<E> where E: PlayerError {
fn from(err: E) -> SelfMatchRunningError<E> {
SelfMatchRunningError::PlayerError(err)
}
}
#[derive(Debug,Eq,PartialEq)]
pub enum SfenStringConvertError {
ToMoveString(ToMoveStringConvertError),
TypeConvertError(TypeConvertError<String>),
InvalidFormat(String),
}
impl fmt::Display for SfenStringConvertError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
SfenStringConvertError::ToMoveString(_) => {
write!(f,"Conversion of move to string representation failed.")
},
SfenStringConvertError::TypeConvertError(_) => {
write!(f,"An error occurred during conversion to sfen string.")
},
SfenStringConvertError::InvalidFormat(ref sfen) => {
write!(f,"The sfen string format is invalid. (passed value: {})", sfen)
}
}
}
}
impl error::Error for SfenStringConvertError {
fn description(&self) -> &str {
match *self {
SfenStringConvertError::ToMoveString(_) => {
"Conversion of move to string representation failed."
},
SfenStringConvertError::TypeConvertError(_) => {
"An error occurred during conversion to sfen string."
},
SfenStringConvertError::InvalidFormat(_) => {
"The sfen string format is invalid."
}
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
SfenStringConvertError::ToMoveString(ref e) => Some(e),
SfenStringConvertError::TypeConvertError(ref e) => Some(e),
SfenStringConvertError::InvalidFormat(_) => None,
}
}
}
impl From<ToMoveStringConvertError> for SfenStringConvertError {
fn from(err: ToMoveStringConvertError) -> SfenStringConvertError {
SfenStringConvertError::ToMoveString(err)
}
}
impl From<TypeConvertError<String>> for SfenStringConvertError {
fn from(err: TypeConvertError<String>) -> SfenStringConvertError {
SfenStringConvertError::TypeConvertError(err)
}
}
#[derive(Debug)]
pub enum KifuWriteError {
Fail(String),
InvalidState(String),
SfenStringConvertError(SfenStringConvertError),
IOError(io::Error),
}
impl fmt::Display for KifuWriteError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
KifuWriteError::Fail(ref s) => write!(f,"There was an error writing kifu. ({})",s),
KifuWriteError::InvalidState(ref e) => write!(f,"There was an error writing kifu. (invalid state, {}).", e),
KifuWriteError::SfenStringConvertError(_) => write!(f,"An error occurred during conversion to sfen string."),
KifuWriteError::IOError(ref e) => write!(f,"IO Error. ({})",e),
}
}
}
impl error::Error for KifuWriteError {
fn description(&self) -> &str {
match *self {
KifuWriteError::Fail(_) => "There was an error writing kifu.",
KifuWriteError::InvalidState(_) => "There was an error writing kifu. (invalid state).",
KifuWriteError::SfenStringConvertError(_) => "An error occurred during conversion to sfen string.",
KifuWriteError::IOError(_) => "There was an error writing kifu. (IO Error).",
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
KifuWriteError::Fail(_) => None,
KifuWriteError::InvalidState(_) => None,
KifuWriteError::SfenStringConvertError(ref e) => Some(e),
KifuWriteError::IOError(ref e) => Some(e),
}
}
}
impl From<SfenStringConvertError> for KifuWriteError {
fn from(err: SfenStringConvertError) -> KifuWriteError {
KifuWriteError::SfenStringConvertError(err)
}
}
impl From<io::Error> for KifuWriteError {
fn from(err:io::Error) -> KifuWriteError {
KifuWriteError::IOError(err)
}
}
pub trait PlayerError: Error + fmt::Debug + Send + 'static {}