#macro #path #file #separator #os #calls #construction

pathsep

a small macro to enable easy path construction in other macro calls

2 releases

0.1.1 Nov 19, 2018
0.1.0 Oct 26, 2018

#1779 in Rust patterns

Download history 47/week @ 2024-04-01 4/week @ 2024-04-08 25/week @ 2024-04-29 1/week @ 2024-05-06 22/week @ 2024-05-13 6/week @ 2024-05-20 26/week @ 2024-06-03 10/week @ 2024-06-10 5/week @ 2024-06-17 40/week @ 2024-06-24 21/week @ 2024-07-08 7/week @ 2024-07-15

68 downloads per month
Used in 2 crates

Apache-2.0/MIT

7KB

Get the path separator for your OS

When you want to include!(_) generated files, cargo will ask you to put them in $OUT_DIR. However, the "usual" way of

include!(concat!(env!("OUT_DIR"), "/somefile.rs"));

will fail on some windows systems, because they fail to understand the / path separator. This crate allows you to replace that with:

include!(join_path!(env!("OUT_DIR"), "somefile.rs"));

This will work on all operating systems. You can create paths starting with the separator by prepending / to the join_path! arguments:

join_path!(/ "usr", "local", "lib");

Usage

Add this to your Cargo.toml:

pathsep = "0.1"

Then you can use #[macro_use] extern crate pathsep; in your crate root. As of Rust 1.30, you can also omit the #[macro_use] and use pathsep::join_path; directly.

License

This code is licensed under the terms of the Apache License 2.0 or the MIT license, at your discretion.


lib.rs:

A small macro that gives us the path separator of the target system

This can be used in conjunction with include!(..) or include_str!(..) and concat!(..) to build paths.

Examples

#[macro_use] extern crate pathsep;

include!(concat!(env!("OUT_DIR"), path_separator!(), "generated.rs"));

The same can be more succinctly written as:

#[macro_use] extern crate pathsep;

include!(path_join!(env!("OUT_DIR"), "generated.rs"));

No runtime deps