Registry / RepositoryTypeScriptRustPython
Rollpie
ReadmeFiles
Versions
Info
Download
0.2.0528.5 KB2026-10-160.1.1542.8 KB2026-10-150.1.0541.1 KB2026-10-15
Version
0.1.0
Copyright
Rollpie, Irohabook
Publisher
math
Published
2026-10-15
Size
541.1 KB
Downloads
9
Checksum
67f9c361d04f05b0299dd8e9ef5e2a0120d67be36205a76945eb5f7ef90443be
Dependencies
None

error.rs

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
//! 解析に失敗したときのエラー

use std::fmt;


/// 解析に失敗した理由と、元の文字列でのその位置
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Error {
    /// 何が起きたかの説明
    pub message: String,
    /// 元の文字列の先頭から数えた文字位置 (0 始まり)
    pub position: usize,
}


impl Error {
    pub fn new(message: impl Into<String>, position: usize) -> Error {
        Error {message: message.into(), position}
    }
}


impl fmt::Display for Error {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        write!(formatter, "{} ({} 文字目)", self.message, self.position + 1)
    }
}


impl std::error::Error for Error {}