1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

実践Rustプログラミング入門 サンプルコードが動かない①

Last updated at Posted at 2022-02-02

はじめに

実践Rustプログラミング入門のp152にある「deriveマクロを使った記述方式」のサンプルが記載通りに動かなかったので動くように修正版を載せておく。
同じように動かない方は参考までに。

動くコード

use clap::Parser;

# [derive(Parser, Debug)]
# [clap(
    name    = "RPN CLI",
    version = "1.0.0",
    author  = "atsutama2",
    about   = "Super awesome sample RPN calculator"
)]

struct Opts {
    #[clap(short, long)]
    verbose: bool,

    #[clap(name = "FILE")]
    formula_file: Option<String>,
}

fn main() {
    let opts = Opts::parse();

    match opts.formula_file {
        Some(file) => println!("File specified: {}", file),
        None => println!("No file sepcifed."),
    }
    println!("Is verboity specified?: {}", opts.verbose);
}
Cargo.toml
[package]
name = "パッケージ名"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "3.0.14", features = ["derive"] }

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?