4
1

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 5 years have passed since last update.

Rustでcharを&strに変換したい

Posted at

初投稿です。
初心者あるあるの文字列操作の一例を投稿します。

0. 環境

  • rustc 1.38.0 (625451e37 2019-09-23)
  • binary: rustc
  • commit-hash: 625451e376bb2e5283fc4741caa0a3e8a2ca4d54
  • commit-date: 2019-09-23
  • host: x86_64-pc-windows-msvc
  • release: 1.38.0
  • LLVM version: 9.0

1. 考え方

char -> String -> &str の順で変換します。

2. 例

fn main() {
    let c = 'a';
    let c_string: String = c.to_string();

    let c_ampersand_str: &str = &c_string;
    // let c_ampersand_str: &str = &c.to_string(); でもOKです

    println!("{}", c_ampersand_str);
}

3. 終わりに

冒頭にもありますが初投稿です。
最近はRustにはまっているので時間があれば, Rust関連の記事を投稿すると思います。

4
1
3

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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?