Skip to content

Commit

Permalink
Change RustcBuilder to use impl Into for fn args
Browse files Browse the repository at this point in the history
This change makes functions for RustcBuilder use `impl Into` to make the
API a bit more convenient to use. This means we can pass in String or
PathBuf or &str or Path giving us a more flexible API with what we can
accept. This is much nicer to work with overall.
  • Loading branch information
mgattozzi committed Jul 21, 2023
1 parent 8784749 commit da5d589
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions src/lib.rs
Expand Up @@ -69,28 +69,28 @@ impl RustcBuilder {
self.edition = Some(edition);
self
}
pub fn out_dir(mut self, out_dir: PathBuf) -> Self {
self.out_dir = Some(out_dir);
pub fn out_dir(mut self, out_dir: impl Into<PathBuf>) -> Self {
self.out_dir = Some(out_dir.into());
self
}
pub fn lib_dir(mut self, lib_dir: PathBuf) -> Self {
self.lib_dir = Some(lib_dir);
pub fn lib_dir(mut self, lib_dir: impl Into<PathBuf>) -> Self {
self.lib_dir = Some(lib_dir.into());
self
}
pub fn crate_name(mut self, crate_name: String) -> Self {
self.crate_name = Some(crate_name);
pub fn crate_name(mut self, crate_name: impl Into<String>) -> Self {
self.crate_name = Some(crate_name.into());
self
}
pub fn crate_type(mut self, crate_type: CrateType) -> Self {
self.crate_type = Some(crate_type);
self
}
pub fn cfg(mut self, cfg: String) -> Self {
self.cfg.push(cfg);
pub fn cfg(mut self, cfg: impl Into<String>) -> Self {
self.cfg.push(cfg.into());
self
}
pub fn externs(mut self, r#extern: String) -> Self {
self.externs.push(r#extern);
pub fn externs(mut self, r#extern: impl Into<String>) -> Self {
self.externs.push(r#extern.into());
self
}

Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Expand Up @@ -22,20 +22,20 @@ fn main() -> Result<(), Box<dyn Error>> {
Rustc::builder()
.edition(Edition::E2021)
.crate_type(CrateType::Lib)
.crate_name("freight".into())
.crate_name("freight")
.out_dir(bootstrap_dir.clone())
.lib_dir(bootstrap_dir.clone())
.cfg("stage1".into())
.cfg("stage1")
.done()
.run("src/lib.rs")?;
Rustc::builder()
.edition(Edition::E2021)
.crate_type(CrateType::Bin)
.crate_name("freight_stage1".into())
.crate_name("freight_stage1")
.out_dir(bootstrap_dir.clone())
.lib_dir(bootstrap_dir)
.cfg("stage1".into())
.externs("freight".into())
.cfg("stage1")
.externs("freight")
.done()
.run("src/main.rs")?;

Expand Down

0 comments on commit da5d589

Please sign in to comment.