For those who are struggling with Rust's cool syntax, our goal is to provide a TOML parser that's as easy as pointing to a menu and eating fast food.
Rustのイケてる構文に難儀している人のために、メニューを指差してファーストフードを食べるぐらい簡単な操作のTOMLパーサーを提供することを目標とします。
Unstable version. It's a tryal and error process. Specifications will change.
不安定版。 試行錯誤中です。 仕様はコロコロ変わるでしょう。
Tomboy is a pun.
トムボーイ(おてんば娘)は語呂合わせです。
References:
Take a look at the repository.
リポジトリを見てください。
shell
cargo run --example comment
cargo run --example example
cargo run --example inline_table
cargo run --example key_value_wip
cargo run --example main
cargo run --example mix_array
cargo run --example spot
cargo run --example table
cargo run --example toml-io-en-a-quick-tour-of-toml-v100rc3
The specifications will gradually solidify.
仕様は少しずつ固めていきます。
You can think that you can't do anything that isn't written here.
ここに書かれていないことは何もできないと思ってもらって構いません。
``rust
//! An exemplary program.
//! 模範的なプログラム。
//!
//!
cargo run --example example`
extern crate tomboytomldom;
use chrono::prelude::{DateTime, Utc}; use tomboytomldom::Toml;
fn main() { // Read a toml. // Toml読取。 let doc = Toml::from_file("./resource/example.toml");
// Read a number.
// 数値読取。
assert_eq!(doc.get_i128_by_key("age"), Some(40));
assert_eq!(doc.get_i128_by_key("int_max"), Some(2147483647));
assert_eq!(doc.get_i128_by_key("int_min"), Some(-2147483648));
assert_eq!(doc.get_f64_by_key("weight"), Some(93.5));
// WIP. Read a string.
// 作業中。 文字列読取。
assert_eq!(doc.get_string_by_key("apple"), Some("pie".to_string()));
assert_eq!(
doc.get_string_by_key("basic_string_letter"),
Some("Hello, world!!".to_string())
);
assert_eq!(
doc.get_string_by_key("basic_string_empty"),
Some("".to_string())
);
assert_eq!(
doc.get_string_by_key("basic_string_escape_backslash"),
Some("\\".to_string())
);
assert_eq!(
doc.get_string_by_key("basic_string_escape_double_quotation"),
Some("\"".to_string())
);
assert_eq!(
doc.get_string_by_key("basic_string_punctuation"),
Some("., ={}[]'\"\\!?".to_string())
);
// TODO assert_eq!(doc.get_string_by_key("basic_string_tab"), Some("a\tb"));
assert_eq!(
doc.get_string_by_key("multiline_basic_string_letter"),
Some(
"Hello,
world!!" .to_string() ) );
assert_eq!(
doc.get_string_by_key("multiline_basic_string_punctuation"),
Some(
"., ={}[]\"'\"\"\\
!?" .tostring() ) ); asserteq!( doc.getstringbykey("multilinebasicstringtrimstart"), Some("The quick brown fox jumps over the lazy dog.".tostring()) ); asserteq!( doc.getstringbykey("multilinebasicstringescapedoublequotation"), Some( " \ " .tostring() ) ); /* // Fixed. println!( "debug|multilinebasicstringtab|{}", doc.getdebugstringbykey("multilinebasicstringtab") ); */ asserteq!( doc.getstringbykey("multilinebasicstringtab"), Some( " a\tb " .tostring() ) );
assert_eq!(
doc.get_string_by_key("literal_string_empty"),
Some("".to_string())
);
assert_eq!(
doc.get_string_by_key("literal_string_letter"),
Some("Hello, world!!".to_string())
);
assert_eq!(
doc.get_string_by_key("literal_string_punctuation"),
Some("., ={}[]\"\\!?".to_string())
);
assert_eq!(
doc.get_string_by_key("multiline_literal_string_letter"),
Some(
"Hello,
world!!" .tostring() ) ); asserteq!( doc.getstringbykey("multilineliteralstringpunctuation"), Some( "., ={}[]'\"\ !?" .to_string() ) );
// Read a boolean.
// 論理値読取。
assert_eq!(doc.get_bool_by_key("adult"), Some(true));
assert_eq!(doc.get_bool_by_key("student"), Some(false));
// DateTime.
// 日付と時刻。
assert_eq!(
doc.get_datetime_utc_by_key("dob"),
Some(
"1979-05-27T07:32:00-08:00"
.parse::<DateTime<Utc>>()
.unwrap()
)
);
} ```
3.14
. 3.14
。"abc"
- Basic string.\
Escape.\r
caridge return.\n
line feed.\t
tab."""abc"""
- Multi-line basic string.\r
caridge return.\n
line feed.\t
tab.'abc'
- Literal string.\r
caridge return.\n
line feed.\t
tab.'''abc'''
- multi-line literal string.\r
caridge return.\n
line feed.\t
tab.1979-05-27T07:32:00-08:00
.