Switch demo code to using std::make_unique

This commit is contained in:
David Tolnay 2020-05-11 20:35:14 -07:00
parent 9808ef177c
commit c13ad23d9c
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
4 changed files with 4 additions and 2 deletions

View File

@ -1,6 +1,7 @@
cxx_library( cxx_library(
name = "demo-cxx", name = "demo-cxx",
srcs = ["demo.cc"], srcs = ["demo.cc"],
compiler_flags = ["-std=c++14"],
visibility = ["PUBLIC"], visibility = ["PUBLIC"],
deps = [ deps = [
":include", ":include",

View File

@ -1,6 +1,7 @@
cc_library( cc_library(
name = "demo-cxx", name = "demo-cxx",
srcs = ["demo.cc"], srcs = ["demo.cc"],
copts = ["-std=c++14"],
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
":include", ":include",

View File

@ -10,7 +10,7 @@ ThingC::ThingC(std::string appname) : appname(std::move(appname)) {}
ThingC::~ThingC() { std::cout << "done with ThingC" << std::endl; } ThingC::~ThingC() { std::cout << "done with ThingC" << std::endl; }
std::unique_ptr<ThingC> make_demo(rust::Str appname) { std::unique_ptr<ThingC> make_demo(rust::Str appname) {
return std::unique_ptr<ThingC>(new ThingC(std::string(appname))); return std::make_unique<ThingC>(std::string(appname));
} }
const std::string &get_name(const ThingC &thing) { return thing.appname; } const std::string &get_name(const ThingC &thing) { return thing.appname; }

View File

@ -1,7 +1,7 @@
fn main() { fn main() {
cxx_build::bridge("src/main.rs") cxx_build::bridge("src/main.rs")
.file("../demo-cxx/demo.cc") .file("../demo-cxx/demo.cc")
.flag_if_supported("-std=c++11") .flag_if_supported("-std=c++14")
.compile("cxxbridge-demo"); .compile("cxxbridge-demo");
println!("cargo:rerun-if-changed=src/main.rs"); println!("cargo:rerun-if-changed=src/main.rs");