Skip to content

Commit

Permalink
Replace ::rust with rust
Browse files Browse the repository at this point in the history
  • Loading branch information
HKalbasi committed Oct 5, 2023
1 parent da3f055 commit a845e7d
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 57 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ for more info.

// Rust values are available in the `::rust` namespace from their absolute path
// in Rust
template <typename T> using Vec = ::rust::std::vec::Vec<T>;
template <typename T> using Option = ::rust::std::option::Option<T>;
template <typename T> using BoxDyn = ::rust::Box<::rust::Dyn<T>>;
template <typename T> using Vec = rust::std::vec::Vec<T>;
template <typename T> using Option = rust::std::option::Option<T>;
template <typename T> using BoxDyn = rust::Box<rust::Dyn<T>>;

// You can implement Rust traits for your classes
template <typename T>
class VectorIterator : public ::rust::std::iter::Iterator<T> {
class VectorIterator : public rust::std::iter::Iterator<T> {
std::vector<T> vec;
size_t pos;

Expand Down Expand Up @@ -60,7 +60,7 @@ int main() {
}
int state = 0;
// You can convert a C++ lambda into a `Box<dyn Fn>` and friends.
auto f = BoxDyn<::rust::Fn<int32_t, int32_t>>::build([&](int32_t x) {
auto f = BoxDyn<rust::Fn<int32_t, int32_t>>::build([&](int32_t x) {
state += x;
std::cout << "hello " << x << " " << state << "\n";
return x * 2;
Expand All @@ -72,7 +72,7 @@ int main() {
// You can convert a C++ type that implements `Trait` to a `Box<dyn Trait>`.
// `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<int32_t>>::make_box<
auto vec_as_iter = BoxDyn<rust::std::iter::Iterator<int32_t>>::make_box<
VectorIterator<int32_t>>(std::move(vec));
// Then use it like a normal Rust value.
auto t = vec_as_iter.collect();
Expand Down
4 changes: 2 additions & 2 deletions book/src/call_cpp_from_rust/rust_impl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::Ref<rust::Str>>
rust::Impl<TagList>::get_value_by_key(::rust::Ref<TagList> self,
::rust::Ref<::rust::Str> key) {
rust::Impl<TagList>::get_value_by_key(rust::Ref<TagList> self,
rust::Ref<rust::Str> key) {
// Your code here
}
```
12 changes: 6 additions & 6 deletions book/src/zngur.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T> using Vec = ::rust::std::vec::Vec<T>;
template <typename T> using Option = ::rust::std::option::Option<T>;
template <typename T> using BoxDyn = ::rust::Box<::rust::Dyn<T>>;
template <typename T> using Vec = rust::std::vec::Vec<T>;
template <typename T> using Option = rust::std::option::Option<T>;
template <typename T> using BoxDyn = rust::Box<rust::Dyn<T>>;

// You can implement Rust traits for your classes
template <typename T>
class VectorIterator : public ::rust::std::iter::Iterator<T> {
class VectorIterator : public rust::std::iter::Iterator<T> {
std::vector<T> vec;
size_t pos;

Expand Down Expand Up @@ -86,7 +86,7 @@ int main() {
}
int state = 0;
// You can convert a C++ lambda into a `Box<dyn Fn>` and friends.
auto f = BoxDyn<::rust::Fn<int32_t, int32_t>>::build([&](int32_t x) {
auto f = BoxDyn<rust::Fn<int32_t, int32_t>>::build([&](int32_t x) {
state += x;
std::cout << "hello " << x << " " << state << "\n";
return x * 2;
Expand All @@ -98,7 +98,7 @@ int main() {
// You can convert a C++ type that implements `Trait` to a `Box<dyn Trait>`.
// `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<int32_t>>::make_box<
auto vec_as_iter = BoxDyn<rust::std::iter::Iterator<int32_t>>::make_box<
VectorIterator<int32_t>>(std::move(vec));
// Then use it like a normal Rust value.
auto t = vec_as_iter.collect();
Expand Down
18 changes: 9 additions & 9 deletions examples/cxx_demo/blobstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "./generated.h"

class BlobStore : public ::rust::crate::BlobStoreTrait {
class BlobStore : public rust::crate::BlobStoreTrait {
class Impl {
friend BlobStore;

Expand All @@ -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<rust::crate::MultiBuf> buf) override {
std::string contents;

// Traverse the caller's chunk iterator.
Expand All @@ -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<rust::core::primitive::str> 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());
Expand All @@ -62,8 +62,8 @@ class BlobStore : public ::rust::crate::BlobStoreTrait {
Impl impl;
};

::rust::Box<::rust::Dyn<::rust::crate::BlobStoreTrait>>
rust::Box<rust::Dyn<rust::crate::BlobStoreTrait>>
rust::exported_functions::new_blob_store_client() {
return ::rust::Box<::rust::Dyn<::rust::crate::BlobStoreTrait>>::make_box<
return rust::Box<rust::Dyn<rust::crate::BlobStoreTrait>>::make_box<
BlobStore>();
}
46 changes: 23 additions & 23 deletions examples/memory_management/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

// Rust values are available in the `::rust` namespace from their absolute path
// in Rust
template <typename T> using Vec = ::rust::std::vec::Vec<T>;
// template <typename T> using Option = ::rust::std::option::Option<T>;
template <typename T> using BoxDyn = ::rust::Box<::rust::Dyn<T>>;
template <typename T> using RmDyn = ::rust::RefMut<::rust::Dyn<T>>;
template <typename T> using Vec = rust::std::vec::Vec<T>;
// template <typename T> using Option = rust::std::option::Option<T>;
template <typename T> using BoxDyn = rust::Box<rust::Dyn<T>>;
template <typename T> using RmDyn = rust::RefMut<rust::Dyn<T>>;
using rust::crate::consume_and_panic;
using rust::crate::consume_n_times;
using rust::crate::PrintOnDrop;
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 {};
}
Expand All @@ -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;
Expand All @@ -38,18 +38,18 @@ int main() {
}
{
std::vector<PrintOnDrop> 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;
}
{
std::cout << "Checkpoint 7" << std::endl;
Vec<PrintOnDrop> vec2 = Vec<PrintOnDrop>::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;
Expand All @@ -61,9 +61,9 @@ int main() {
auto holder = BoxDyn<PrintOnDropConsumer>::make_box<CppPrintOnDropHolder>(
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;
Expand All @@ -74,35 +74,35 @@ int main() {
std::cout << "Checkpoint 15" << std::endl;
auto holder = RmDyn<PrintOnDropConsumer>::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<PrintOnDrop> vec2 = Vec<PrintOnDrop>::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();
{
Expand Down
8 changes: 4 additions & 4 deletions examples/osmium/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> reader,
BendHandler handler) {
rust::Tuple<> rust::exported_functions::apply(rust::Ref<Reader> reader,
BendHandler handler) {
using IndexType =
osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type,
osmium::Location>;
Expand All @@ -53,8 +53,8 @@ rust::Ref<TagList> rust::Impl<Way>::tags(rust::Ref<Way> self) {
}

rust::std::option::Option<rust::Ref<rust::Str>>
rust::Impl<TagList>::get_value_by_key(::rust::Ref<TagList> self,
::rust::Ref<::rust::Str> key) {
rust::Impl<TagList>::get_value_by_key(rust::Ref<TagList> self,
rust::Ref<rust::Str> 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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/rustyline/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions examples/simple/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

// Rust values are available in the `::rust` namespace from their absolute path
// in Rust
template <typename T> using Vec = ::rust::std::vec::Vec<T>;
template <typename T> using Option = ::rust::std::option::Option<T>;
template <typename T> using BoxDyn = ::rust::Box<::rust::Dyn<T>>;
template <typename T> using Vec = rust::std::vec::Vec<T>;
template <typename T> using Option = rust::std::option::Option<T>;
template <typename T> using BoxDyn = rust::Box<rust::Dyn<T>>;

// You can implement Rust traits for your classes
template <typename T>
class VectorIterator : public ::rust::std::iter::Iterator<T> {
class VectorIterator : public rust::std::iter::Iterator<T> {
std::vector<T> vec;
size_t pos;

Expand Down Expand Up @@ -50,7 +50,7 @@ int main() {
}
int state = 0;
// You can convert a C++ lambda into a `Box<dyn Fn>` and friends.
auto f = BoxDyn<::rust::Fn<int32_t, int32_t>>::build([&](int32_t x) {
auto f = BoxDyn<rust::Fn<int32_t, int32_t>>::build([&](int32_t x) {
state += x;
std::cout << "hello " << x << " " << state << "\n";
return x * 2;
Expand All @@ -62,7 +62,7 @@ int main() {
// You can convert a C++ type that implements `Trait` to a `Box<dyn Trait>`.
// `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<int32_t>>::make_box<
auto vec_as_iter = BoxDyn<rust::std::iter::Iterator<int32_t>>::make_box<
VectorIterator<int32_t>>(std::move(vec));
// Then use it like a normal Rust value.
auto t = vec_as_iter.collect();
Expand Down

0 comments on commit a845e7d

Please sign in to comment.