From a845e7d8c6159bd233e71b4e61c1c91f2a8f3f31 Mon Sep 17 00:00:00 2001 From: hkalbasi Date: Thu, 5 Oct 2023 21:13:12 +0330 Subject: [PATCH] Replace `::rust` with `rust` --- README.md | 12 +++---- book/src/call_cpp_from_rust/rust_impl.md | 4 +-- book/src/zngur.md | 12 +++---- examples/cxx_demo/blobstore.cpp | 18 +++++----- examples/memory_management/main.cpp | 46 ++++++++++++------------ examples/osmium/impl.cpp | 8 ++--- examples/rustyline/main.cpp | 2 +- examples/simple/main.cpp | 12 +++---- 8 files changed, 57 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index bcc6410..285406e 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ for more info. // Rust values are available in the `::rust` namespace from their absolute path // in Rust -template using Vec = ::rust::std::vec::Vec; -template using Option = ::rust::std::option::Option; -template using BoxDyn = ::rust::Box<::rust::Dyn>; +template using Vec = rust::std::vec::Vec; +template using Option = rust::std::option::Option; +template using BoxDyn = rust::Box>; // You can implement Rust traits for your classes template -class VectorIterator : public ::rust::std::iter::Iterator { +class VectorIterator : public rust::std::iter::Iterator { std::vector vec; size_t pos; @@ -60,7 +60,7 @@ int main() { } int state = 0; // You can convert a C++ lambda into a `Box` and friends. - auto f = BoxDyn<::rust::Fn>::build([&](int32_t x) { + auto f = BoxDyn>::build([&](int32_t x) { state += x; std::cout << "hello " << x << " " << state << "\n"; return x * 2; @@ -72,7 +72,7 @@ int main() { // You can convert a C++ type that implements `Trait` to a `Box`. // `make_box` is similar to the `make_unique`, it takes constructor arguments // and construct it inside the `Box` (instead of `unique_ptr`). - auto vec_as_iter = BoxDyn<::rust::std::iter::Iterator>::make_box< + auto vec_as_iter = BoxDyn>::make_box< VectorIterator>(std::move(vec)); // Then use it like a normal Rust value. auto t = vec_as_iter.collect(); diff --git a/book/src/call_cpp_from_rust/rust_impl.md b/book/src/call_cpp_from_rust/rust_impl.md index 9068129..56c3a8f 100644 --- a/book/src/call_cpp_from_rust/rust_impl.md +++ b/book/src/call_cpp_from_rust/rust_impl.md @@ -28,8 +28,8 @@ And you need to implement that in a `.cpp` file, and link it to the crate: ```C++ rust::std::option::Option> -rust::Impl::get_value_by_key(::rust::Ref self, - ::rust::Ref<::rust::Str> key) { +rust::Impl::get_value_by_key(rust::Ref self, + rust::Ref key) { // Your code here } ``` diff --git a/book/src/zngur.md b/book/src/zngur.md index 9c3fc93..f31769a 100644 --- a/book/src/zngur.md +++ b/book/src/zngur.md @@ -41,13 +41,13 @@ from C++ that operate on Rust types. // Rust values are available in the `::rust` namespace from their absolute path // in Rust -template using Vec = ::rust::std::vec::Vec; -template using Option = ::rust::std::option::Option; -template using BoxDyn = ::rust::Box<::rust::Dyn>; +template using Vec = rust::std::vec::Vec; +template using Option = rust::std::option::Option; +template using BoxDyn = rust::Box>; // You can implement Rust traits for your classes template -class VectorIterator : public ::rust::std::iter::Iterator { +class VectorIterator : public rust::std::iter::Iterator { std::vector vec; size_t pos; @@ -86,7 +86,7 @@ int main() { } int state = 0; // You can convert a C++ lambda into a `Box` and friends. - auto f = BoxDyn<::rust::Fn>::build([&](int32_t x) { + auto f = BoxDyn>::build([&](int32_t x) { state += x; std::cout << "hello " << x << " " << state << "\n"; return x * 2; @@ -98,7 +98,7 @@ int main() { // You can convert a C++ type that implements `Trait` to a `Box`. // `make_box` is similar to the `make_unique`, it takes constructor arguments // and construct it inside the `Box` (instead of `unique_ptr`). - auto vec_as_iter = BoxDyn<::rust::std::iter::Iterator>::make_box< + auto vec_as_iter = BoxDyn>::make_box< VectorIterator>(std::move(vec)); // Then use it like a normal Rust value. auto t = vec_as_iter.collect(); diff --git a/examples/cxx_demo/blobstore.cpp b/examples/cxx_demo/blobstore.cpp index 97de36d..f4a4f00 100644 --- a/examples/cxx_demo/blobstore.cpp +++ b/examples/cxx_demo/blobstore.cpp @@ -5,7 +5,7 @@ #include "./generated.h" -class BlobStore : public ::rust::crate::BlobStoreTrait { +class BlobStore : public rust::crate::BlobStoreTrait { class Impl { friend BlobStore; @@ -17,7 +17,7 @@ class BlobStore : public ::rust::crate::BlobStoreTrait { }; public: - uint64_t put(::rust::RefMut<::rust::crate::MultiBuf> buf) override { + uint64_t put(rust::RefMut buf) override { std::string contents; // Traverse the caller's chunk iterator. @@ -39,14 +39,14 @@ class BlobStore : public ::rust::crate::BlobStoreTrait { return blob_id; } - ::rust::Unit tag(::uint64_t blob_id, - ::rust::Ref<::rust::core::primitive::str> tag) override { + rust::Unit tag(::uint64_t blob_id, + rust::Ref tag) override { impl.blobs[blob_id].tags.emplace((char *)tag.as_ptr(), tag.len()); - return ::rust::Unit{}; + return rust::Unit{}; } - ::rust::crate::BlobMetadata metadata(::uint64_t blob_id) override { - ::rust::crate::BlobMetadata r = ::rust::crate::BlobMetadata::default_(); + rust::crate::BlobMetadata metadata(::uint64_t blob_id) override { + rust::crate::BlobMetadata r = rust::crate::BlobMetadata::default_(); auto blob = impl.blobs.find(blob_id); if (blob != impl.blobs.end()) { r.set_size(blob->second.data.size()); @@ -62,8 +62,8 @@ class BlobStore : public ::rust::crate::BlobStoreTrait { Impl impl; }; -::rust::Box<::rust::Dyn<::rust::crate::BlobStoreTrait>> +rust::Box> rust::exported_functions::new_blob_store_client() { - return ::rust::Box<::rust::Dyn<::rust::crate::BlobStoreTrait>>::make_box< + return rust::Box>::make_box< BlobStore>(); } diff --git a/examples/memory_management/main.cpp b/examples/memory_management/main.cpp index 4f57b2c..ae19f7e 100644 --- a/examples/memory_management/main.cpp +++ b/examples/memory_management/main.cpp @@ -5,10 +5,10 @@ // Rust values are available in the `::rust` namespace from their absolute path // in Rust -template using Vec = ::rust::std::vec::Vec; -// template using Option = ::rust::std::option::Option; -template using BoxDyn = ::rust::Box<::rust::Dyn>; -template using RmDyn = ::rust::RefMut<::rust::Dyn>; +template using Vec = rust::std::vec::Vec; +// template using Option = rust::std::option::Option; +template using BoxDyn = rust::Box>; +template using RmDyn = rust::RefMut>; using rust::crate::consume_and_panic; using rust::crate::consume_n_times; using rust::crate::PrintOnDrop; @@ -16,7 +16,7 @@ using rust::crate::PrintOnDropConsumer; using rust::crate::PrintOnDropPair; class CppPrintOnDropHolder : public PrintOnDropConsumer { - ::rust::Unit consume(PrintOnDrop p) override { + rust::Unit consume(PrintOnDrop p) override { item = std::move(p); return {}; } @@ -25,9 +25,9 @@ class CppPrintOnDropHolder : public PrintOnDropConsumer { }; int main() { - auto p1 = PrintOnDrop(::rust::Str::from_char_star("A")); - auto p2 = PrintOnDrop(::rust::Str::from_char_star("B")); - auto p3 = PrintOnDrop(::rust::Str::from_char_star("C")); + auto p1 = PrintOnDrop(rust::Str::from_char_star("A")); + auto p2 = PrintOnDrop(rust::Str::from_char_star("B")); + auto p3 = PrintOnDrop(rust::Str::from_char_star("C")); std::cout << "Checkpoint 1" << std::endl; p2 = std::move(p1); std::cout << "Checkpoint 2" << std::endl; @@ -38,9 +38,9 @@ int main() { } { std::vector vec1; - vec1.emplace_back(::rust::Str::from_char_star("cpp_V1")); - vec1.emplace_back(::rust::Str::from_char_star("cpp_V2")); - vec1.emplace_back(::rust::Str::from_char_star("cpp_V3")); + vec1.emplace_back(rust::Str::from_char_star("cpp_V1")); + vec1.emplace_back(rust::Str::from_char_star("cpp_V2")); + vec1.emplace_back(rust::Str::from_char_star("cpp_V3")); std::cout << "Checkpoint 5" << std::endl; vec1.pop_back(); std::cout << "Checkpoint 6" << std::endl; @@ -48,8 +48,8 @@ int main() { { std::cout << "Checkpoint 7" << std::endl; Vec vec2 = Vec::new_(); - vec2.push(PrintOnDrop(::rust::Str::from_char_star("rust_V1"))); - vec2.push(PrintOnDrop(::rust::Str::from_char_star("rust_V2"))); + vec2.push(PrintOnDrop(rust::Str::from_char_star("rust_V1"))); + vec2.push(PrintOnDrop(rust::Str::from_char_star("rust_V2"))); std::cout << "Checkpoint 8" << std::endl; vec2.clone(); // Clone and drop immediately std::cout << "Checkpoint 9" << std::endl; @@ -61,9 +61,9 @@ int main() { auto holder = BoxDyn::make_box( std::move(c)); std::cout << "Checkpoint 11" << std::endl; - consume_n_times(holder.deref_mut(), ::rust::Str::from_char_star("P"), 3); + consume_n_times(holder.deref_mut(), rust::Str::from_char_star("P"), 3); std::cout << "Checkpoint 12" << std::endl; - consume_n_times(holder.deref_mut(), ::rust::Str::from_char_star("Q"), 2); + consume_n_times(holder.deref_mut(), rust::Str::from_char_star("Q"), 2); std::cout << "Checkpoint 13" << std::endl; } std::cout << "Checkpoint 14" << std::endl; @@ -74,35 +74,35 @@ int main() { std::cout << "Checkpoint 15" << std::endl; auto holder = RmDyn::build(c); std::cout << "Checkpoint 16" << std::endl; - consume_n_times(holder, ::rust::Str::from_char_star("P2"), 3); + consume_n_times(holder, rust::Str::from_char_star("P2"), 3); std::cout << "Checkpoint 17" << std::endl; - consume_n_times(holder, ::rust::Str::from_char_star("Q2"), 2); + consume_n_times(holder, rust::Str::from_char_star("Q2"), 2); std::cout << "Checkpoint 18" << std::endl; } std::cout << "Checkpoint 19" << std::endl; } std::cout << "Checkpoint 20" << std::endl; try { - PrintOnDrop a{::rust::Str::from_char_star("A")}; + PrintOnDrop a{rust::Str::from_char_star("A")}; std::cout << "Checkpoint 21" << std::endl; consume_and_panic(a.clone(), false); std::cout << "Checkpoint 22" << std::endl; - consume_and_panic(::rust::Str::from_char_star("B"), true); + consume_and_panic(rust::Str::from_char_star("B"), true); std::cout << "Checkpoint 23" << std::endl; } catch (rust::Panic e) { std::cout << "Checkpoint 24" << std::endl; } { std::cout << "Checkpoint 25" << std::endl; - PrintOnDropPair p{::rust::Str::from_char_star("first"), - ::rust::Str::from_char_star("second")}; + PrintOnDropPair p{rust::Str::from_char_star("first"), + rust::Str::from_char_star("second")}; std::cout << "Checkpoint 26" << std::endl; } { std::cout << "Checkpoint 27" << std::endl; Vec vec2 = Vec::new_(); - vec2.push(PrintOnDrop(::rust::Str::from_char_star("elem1"))); - vec2.push(PrintOnDrop(::rust::Str::from_char_star("elem2"))); + vec2.push(PrintOnDrop(rust::Str::from_char_star("elem1"))); + vec2.push(PrintOnDrop(rust::Str::from_char_star("elem2"))); std::cout << "Checkpoint 28" << std::endl; vec2.get(0).unwrap().clone(); { diff --git a/examples/osmium/impl.cpp b/examples/osmium/impl.cpp index fde3bd1..72aa2f6 100644 --- a/examples/osmium/impl.cpp +++ b/examples/osmium/impl.cpp @@ -31,8 +31,8 @@ class RustHandler : public osmium::handler::Handler { RustHandler(BendHandler &&inner) : inner(std::move(inner)) {} }; -::rust::Tuple<> rust::exported_functions::apply(::rust::Ref reader, - BendHandler handler) { +rust::Tuple<> rust::exported_functions::apply(rust::Ref reader, + BendHandler handler) { using IndexType = osmium::index::map::SparseMemArray; @@ -53,8 +53,8 @@ rust::Ref rust::Impl::tags(rust::Ref self) { } rust::std::option::Option> -rust::Impl::get_value_by_key(::rust::Ref self, - ::rust::Ref<::rust::Str> key) { +rust::Impl::get_value_by_key(rust::Ref self, + rust::Ref key) { string cpp_key{(const char *)key.as_ptr(), key.len()}; auto value = self.cpp().get_value_by_key(cpp_key.c_str()); if (value == nullptr) { diff --git a/examples/rustyline/main.cpp b/examples/rustyline/main.cpp index bd9c6ce..c790eff 100644 --- a/examples/rustyline/main.cpp +++ b/examples/rustyline/main.cpp @@ -6,7 +6,7 @@ #include "./generated.h" int main() { - auto editor = ::rust::rustyline::DefaultEditor::new_().unwrap(); + auto editor = rust::rustyline::DefaultEditor::new_().unwrap(); if (editor.load_history(rust::Str::from_char_star("history.txt")).is_err()) { std::cout << "No previous history." << std::endl; } diff --git a/examples/simple/main.cpp b/examples/simple/main.cpp index 1cdce9a..5d91d5c 100644 --- a/examples/simple/main.cpp +++ b/examples/simple/main.cpp @@ -5,13 +5,13 @@ // Rust values are available in the `::rust` namespace from their absolute path // in Rust -template using Vec = ::rust::std::vec::Vec; -template using Option = ::rust::std::option::Option; -template using BoxDyn = ::rust::Box<::rust::Dyn>; +template using Vec = rust::std::vec::Vec; +template using Option = rust::std::option::Option; +template using BoxDyn = rust::Box>; // You can implement Rust traits for your classes template -class VectorIterator : public ::rust::std::iter::Iterator { +class VectorIterator : public rust::std::iter::Iterator { std::vector vec; size_t pos; @@ -50,7 +50,7 @@ int main() { } int state = 0; // You can convert a C++ lambda into a `Box` and friends. - auto f = BoxDyn<::rust::Fn>::build([&](int32_t x) { + auto f = BoxDyn>::build([&](int32_t x) { state += x; std::cout << "hello " << x << " " << state << "\n"; return x * 2; @@ -62,7 +62,7 @@ int main() { // You can convert a C++ type that implements `Trait` to a `Box`. // `make_box` is similar to the `make_unique`, it takes constructor arguments // and construct it inside the `Box` (instead of `unique_ptr`). - auto vec_as_iter = BoxDyn<::rust::std::iter::Iterator>::make_box< + auto vec_as_iter = BoxDyn>::make_box< VectorIterator>(std::move(vec)); // Then use it like a normal Rust value. auto t = vec_as_iter.collect();