LogoDuyệtSr. Data Engineer
HomeAboutPhotosInsightsCV

Footer

Logo

Resources

  • Rust Tiếng Việt
  • /archives
  • /series
  • /tags
  • Status

me@duyet.net

  • About
  • LinkedIn
  • Resume
  • Projects

© 2026 duyet.net | Sr. Data Engineer | 2026-02-27

Rust: indoc

Chuỗi bài viết Rust Tiếng Việt là một trong những nội dung nằm trong sách Rust Tiếng Việt

indoc là một crate nhỏ nhưng hữu ích giúp canh lề (indented documents). indoc!() macro nhận multiline string và un-indents lúc compile time, xoá tất cả khoảng trắng đầu tiên trên cách dòng dựa theo dòng đầu tiên.

File: Cargo.toml

[dependencies]
indoc = "1"

Ví dụ:

use indoc::indoc;

fn main() {
    let testing = indoc! {"
        def hello():
            print('Hello, world!')

        hello()
    "};

    let expected = "def hello():\n    print('Hello, world!')\n\nhello()\n";
    assert_eq!(testing, expected);
}

indoc cũng hoạt động với raw string r# ... # và byte string b" ... ".

References

  • https://rust-tieng-viet.github.io/crates/indoc.html
  • https://docs.rs/indoc/latest/indoc/
  • https://github.com/dtolnay/indoc
Aug 6, 2022·4 years ago
|Rust|
RustVietnameseRust Tiếng Việt
|Edit|

Related Posts

Rust: Rayon - A data parallelism library for Rust

rayon là thư viện data-parallelism cho Rust, gọn nhẹ và dễ dàng convert từ code tính toán tuần tự sang song song mà vẫn đảm bảo không lỗi data-race.

Aug 6, 2022·4 years ago
Read more

Rust: Box

Tất cả giá trị trên Rust mặc định đều được allocated trên stack. Giá trị có thể được boxed, allocated trên heap bằng cách sử dụng Box<T>. Box<T> là một smart pointer của Rust cho phép allocated trên heap giá trị có kiểu T, còn pointer trỏ đến giá trị đó sẽ nằm trên stack.

Mar 5, 2022·4 years ago
Read more

Rust Design Pattern: Builder Pattern

Builder được sử dụng cực kỳ phổ biến trong Rust so với các ngôn ngữ khác, bởi vì Rust không có overloading.

Feb 13, 2022·4 years ago
Read more

Rust Design Pattern: Command Pattern

Ý tưởng cơ bản của Command Pattern là tách các actions thành các object riêng và gọi chúng thông qua parameters.

Feb 13, 2022·4 years ago
Read more
On this page
  • References
On this page
  • References