#source-string #byte #path #macro #cross-platform #variadic

nightly macro include_path

A cross-platform way to include! source, strings and bytes

2 releases

0.1.1 Sep 19, 2021
0.1.0 Sep 19, 2021

#8 in #source-string

36 downloads per month

Unlicense

7KB
85 lines

include_path

This crate provides an implementation of a proposed set of macros to complement the existing include_*macros in Rust, taking a variadic set of arguments, combining them into a platform-specific path string at compilation time, and returning the corresponding underlying macros

You can view examples of usage in the crate documentation.


lib.rs:

A cross-platform way to include! source, strings and bytes

This crate provides an implementation of a proposed set of macros to complement the existing include_*macros in Rust, taking a variadic set of arguments, combining them into a platform-specific path string at compilation time, and returning the corresponding underlying macros

Examples

// This code assumes the file "../res-tests/include.txt" exists and contains the following:
// ```
// include = "Test String"
// ```
// This code will compile in both Windows systems and Unix-based systems

use include_path::include_path;
let include;
include_path!("..","res-tests","include.txt");
assert_eq!("Test String",include);
// This code assumes the file "../res-tests/include_bytes.txt" exists and contains the following UTF-8 encoded text:
// ```
// Test Bytes
// ```
// This code will compile in both Windows systems and Unix-based systems

use include_path::include_path_bytes;

let include_bytes = include_path_bytes!("..","res-tests","include_bytes.txt");
assert_eq!("Test Bytes".as_bytes(),include_bytes);
// This code assumes the file "../res-tests/include_str.txt" exists and contains the following:
// ```
// Test String
// ```
// This code will compile in both Windows systems and Unix-based systems

use include_path::include_path_str;

let include_str = include_path_str!("..","res-tests","include_str.txt");
assert_eq!("Test String",include_str);

Dependencies

~235KB