Browse Source

Merge branch 'into-option-str' of https://github.com/laumann/gcc-rs

cmd
Alex Crichton 7 years ago
parent
commit
5824f286a3
  1. 2
      gcc-test/build.rs
  2. 25
      src/lib.rs
  3. 4
      tests/test.rs

2
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()

25
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<Option<&'a str>>>(&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<Option<&'a str>>>(&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<Option<&'a str>>>(&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

4
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");

Loading…
Cancel
Save