diff --git a/gcc-test/build.rs b/gcc-test/build.rs index c78e8dd..0379a60 100644 --- a/gcc-test/build.rs +++ b/gcc-test/build.rs @@ -14,7 +14,7 @@ fn main() { .flag_if_supported("-Wall") .flag_if_supported("-Wfoo-bar-this-flag-does-not-exist") .define("FOO", None) - .define("BAR", Some("1")) + .define("BAR", "1") .compile("libfoo.a"); gcc::Config::new() diff --git a/src/lib.rs b/src/lib.rs index 7106e32..8686da3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -261,12 +261,12 @@ impl Config { /// ```no_run /// gcc::Config::new() /// .file("src/foo.c") - /// .define("FOO", Some("BAR")) + /// .define("FOO", "BAR") /// .define("BAZ", None) /// .compile("foo"); /// ``` - pub fn define(&mut self, var: &str, val: Option<&str>) -> &mut Config { - self.definitions.push((var.to_string(), val.map(|s| s.to_string()))); + pub fn define<'a, V: Into>>(&mut self, var: &str, val: V) -> &mut Config { + self.definitions.push((var.to_string(), val.into().map(|s| s.to_string()))); self } @@ -402,12 +402,12 @@ impl Config { /// Set warnings into errors flag. /// /// Disabled by default. - /// - /// Warning: turning warnings into errors only make sense + /// + /// Warning: turning warnings into errors only make sense /// if you are a developer of the crate using gcc-rs. /// Some warnings only appear on some architecture or - /// specific version of the compiler. Any user of this crate, - /// or any other crate depending on it, could fail during + /// specific version of the compiler. Any user of this crate, + /// or any other crate depending on it, could fail during /// compile time. /// /// # Example @@ -466,11 +466,11 @@ impl Config { /// gcc::Config::new() /// .file("src/foo.c") /// .shared_flag(true) - /// .cpp_link_stdlib(Some("stdc++")) + /// .cpp_link_stdlib("stdc++") /// .compile("libfoo.so"); /// ``` - pub fn cpp_link_stdlib(&mut self, cpp_link_stdlib: Option<&str>) -> &mut Config { - self.cpp_link_stdlib = Some(cpp_link_stdlib.map(|s| s.into())); + pub fn cpp_link_stdlib<'a, V: Into>>(&mut self, cpp_link_stdlib: V) -> &mut Config { + self.cpp_link_stdlib = Some(cpp_link_stdlib.into().map(|s| s.into())); self } @@ -504,10 +504,11 @@ impl Config { /// ```no_run /// gcc::Config::new() /// .file("src/foo.c") - /// .cpp_set_stdlib(Some("c++")) + /// .cpp_set_stdlib("c++") /// .compile("libfoo.a"); /// ``` - pub fn cpp_set_stdlib(&mut self, cpp_set_stdlib: Option<&str>) -> &mut Config { + pub fn cpp_set_stdlib<'a, V: Into>>(&mut self, cpp_set_stdlib: V) -> &mut Config { + let cpp_set_stdlib = cpp_set_stdlib.into(); self.cpp_set_stdlib = cpp_set_stdlib.map(|s| s.into()); self.cpp_link_stdlib(cpp_set_stdlib); self diff --git a/tests/test.rs b/tests/test.rs index d1eef18..f66c44b 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -175,7 +175,7 @@ fn gnu_include() { fn gnu_define() { let test = Test::gnu(); test.gcc() - .define("FOO", Some("bar")) + .define("FOO", "bar") .define("BAR", None) .file("foo.c") .compile("libfoo.a"); @@ -289,7 +289,7 @@ fn msvc_include() { fn msvc_define() { let test = Test::msvc(); test.gcc() - .define("FOO", Some("bar")) + .define("FOO", "bar") .define("BAR", None) .file("foo.c") .compile("libfoo.a");