0
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?

Rustでprintlnとdbgの確認

0
Last updated at Posted at 2025-12-29

Hello world をやってみて、いろいろ確認

参考

リテラルのみ

  • 文字列
    • "Hello"
    • r##"#06-6012-3456"##
  • 整数
    • 2
    • 0xff
    • 0b101
  • 小数
    • 3.14
    • 1.2e-4
  • 文字
    • 🦊
  • 論理
    • true
  • バイト
    • b'k'
    • b"bytes"

ソース

fn main() {
    let s1 = "Hello";
    let s2 = r##"#06-6012-3456"##;
    let i3 = 2;
    let i4 = 0xff;
    let i5 = 0b101;
    let f6 = 3.14;
    let f7 = 1.2e-4;
    let c8 = '🦊';
    let b9 = true;
    let ba = b'k';
    let bb = b"bytes";
    let df_a = dbg!(format!("{} {} {} {} {} {} {} {} {} {} {:?}", s1, s2, i3, i4, i5, f6, f7, c8, b9, ba, bb));
    println!("{}", df_a);
    
    let t_12 = dbg!(s1, s2);
    let t_23 = dbg!(s2, i3);
    let t_34 = dbg!(i3, i4);
    let t_45 = dbg!(i4, i5);
    let t_56 = dbg!(i5, f6);
    let t_67 = dbg!(f6, f7);
    let t_78 = dbg!(f7, c8);
    let t_89 = dbg!(c8, b9);
    let t_9a = dbg!(b9, ba);
    let t_ab = dbg!(ba, bb);
    let t_b1 = dbg!(bb, s1);
    let df_b = dbg!(format!("{} {} {} {} {} {} {} {} {} {} {:?}", t_12.0, t_23.0, t_34.0, t_45.0, t_56.0, t_67.0, t_78.0, t_89.0, t_9a.0, t_ab.0, t_b1.0));
    println!("{}", df_b);
}

出力

Hello #06-6012-3456 2 255 5 3.14 0.00012 🦊 true 107 [98, 121, 116, 101, 115]
Hello #06-6012-3456 2 255 5 3.14 0.00012 🦊 true 107 [98, 121, 116, 101, 115]

String

ソース

fn main() {
    let l1 = "Hello";
    let l2 = "World";
    let l3 = "test";
    let l13 = dbg!(l1, l3);
    let l23 = dbg!(l2, l3);
    let l4 = dbg!(format!("{} {}", l13.0, l23.0));
    println!("{}", l4);
    
    let s1 = String::from(l1);
    let s2 = String::from(l2);
    //let s3 = String::from(l3);
    let s13 = dbg!(s1);
    let s23 = dbg!(s2);
    let s4 = dbg!(format!("{} {}", s13, s23));
    println!("{}", s4);
    
    let ss1 = String::from(l1);
    let ss2 = String::from(l2);
    let ss3 = String::from(l3);
    let ss13 = dbg!(ss1, &ss3);
    let ss23 = dbg!(ss2, &ss3);
    let ss4 = dbg!(format!("{} {}", ss13.0, ss23.0));
    println!("{}", ss4);
    
    let sss1 = String::from(l1);
    let sss2 = String::from(l2);
    let sss3 = String::from(l3);
    let sss123 = dbg!(&sss1, &sss2, &sss3);
    let sss213 = dbg!(&sss2, &sss1, &sss3);
    let sss4 = dbg!(format!("{} {}", sss123.0, sss213.0));
    println!("{}", sss4);
}

出力

Hello World
Hello World
Hello World
Hello World
0
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
0
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?