Skip to content

Commit 7127590

Browse files
committed
Merge pull request #17 from aochagavia/asref
Use AsRef in the compile function
2 parents 638cd11 + 148e386 commit 7127590

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

example/addressbook/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
extern crate capnpc;
22

33
fn main() {
4-
::capnpc::compile(&::std::path::Path::new("."),
5-
&[::std::path::Path::new("addressbook.capnp")]).unwrap();
4+
::capnpc::compile(".", &["addressbook.capnp"]).unwrap();
65
}

src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ pub mod schema_capnp;
5454
pub mod codegen;
5555
pub mod schema;
5656

57-
pub fn compile(prefix : &::std::path::Path, files : &[&::std::path::Path]) -> ::capnp::Result<()> {
57+
use std::path::Path;
5858

59+
pub fn compile<P1: AsRef<Path> + ?Sized, P2: AsRef<Path> + ?Sized>(prefix : &P1, files : &[&P2]) -> ::capnp::Result<()>
60+
{
5961
// Find the absolute path of `cat`.
6062
//
6163
// TODO: Once a released version of `capnp compile` includes the '-o -' option, switch to
@@ -70,10 +72,10 @@ pub fn compile(prefix : &::std::path::Path, files : &[&::std::path::Path]) -> ::
7072

7173
let mut command = ::std::process::Command::new("capnp");
7274
command.arg("compile").arg("-o").arg(&::std::str::from_utf8(&cat_file).unwrap().trim())
73-
.arg(&format!("--src-prefix={}", prefix.display()));
75+
.arg(&format!("--src-prefix={}", prefix.as_ref().display()));
7476

7577
for file in files.iter() {
76-
command.arg(&format!("{}", file.display()));
78+
command.arg(&format!("{}", file.as_ref().display()));
7779
}
7880

7981
command.stdout(::std::process::Stdio::piped());

0 commit comments

Comments
 (0)