Closed tomoyuki-nakabayashi closed 5 years ago
nightly compilerが必要なのか。
$ rustc --pretty expanded src/main.rs
error: the `-Z unstable-options` flag must also be passed to enable the flag `pretty`
$ rustc --pretty expanded -Z unstable-options src/main.rs
error: the option `Z` is only accepted on the nightly compiler
$ rustup override add nightly
$ rustc --pretty expanded -Z unstable-options src/main.rs
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use ::std::prelude::v1::*;
#[macro_use]
extern crate std;
macro_rules! my_vec(( $ ( $ x : expr ) , * ) => {
{
let mut temp_vec = Vec :: new ( ) ; $ (
temp_vec . push ( $ x ) ; ) * temp_vec } } ;);
fn main() {
let v =
{
let mut temp_vec = Vec::new();
temp_vec.push(1);
temp_vec.push(2);
temp_vec.push(3);
temp_vec
};
{
::io::_print(::std::fmt::Arguments::new_v1_formatted(&["", "\n"],
&match (&&v,) {
(arg0,) =>
[::std::fmt::ArgumentV1::new(arg0,
::std::fmt::Debug::fmt)],
},
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},}]));
};
}
なるほどね~。
プログラミングRust p.492
log_syntax!()マクロ
trace_macros!(true);
tt: token treeは(...), [...], {...}などのカッコで囲まれている部分すべて、または、カッコで囲まれていない単一のトークンにマッチする。
プログラミングRust p.495のunittest、JSONオブジェクトをvec!で作っているが、HashMapの間違いか?
let hand_coded_value =
Json::Array(vec![
Json::Object(Box::new([
("pitch".to_string(), Json::Number(440.0))
].iter().cloned().collect::<HashMap<String, Json>>()))
]);
vec!だとコンパイルエラーになるし。
match opcode {
Cld => meta_inst!(opcode, false, false, None, None),
Lea => meta_inst!(opcode, true, false, None, Some(UDWord)),
MovRmSreg => meta_inst!(opcode, true, false, None, None),
Xor => meta_inst!(opcode, true, false, None, None),
Hlt => meta_inst!(opcode, false, false, None, None),
_ => None,
}
ちょっとすっきりした。 フィールド名なくなったからこのままではダメ。 matchごとmacro化したいな。
かなり良くなった。
93e5170619250d1d5c4137dae950655978136ca5
まぁ一旦良いでしょう。
https://doc.rust-jp.rs/the-rust-programming-language-ja/1.6/book/macros.html
これは覚えておく必要がある。