Movatterモバイル変換


[0]ホーム

URL:


std

Macroinclude_str

1.38.0 ·Source
macro_rules! include_str {    ($file:expr $(,)?) => { ... };}
Expand description

Includes a UTF-8 encoded file as a string.

The file is located relative to the current file (similarly to howmodules are found). The provided path is interpreted in a platform-specificway at compile time. So, for instance, an invocation with a Windows pathcontaining backslashes\ would not compile correctly on Unix.

This macro will yield an expression of type&'static str which is thecontents of the file.

§Examples

Assume there are two files in the same directory with the followingcontents:

File ‘spanish.in’:

adiós

File ‘main.rs’:

fnmain() {letmy_str =include_str!("spanish.in");assert_eq!(my_str,"adiós\n");print!("{my_str}");}

Compiling ‘main.rs’ and running the resulting binary will print “adiós”.


[8]ページ先頭

©2009-2025 Movatter.jp