Comments (2)
Thanks! I agree that an implicit construction from char const*
to rust::String
should be fine. I ended up changing only these two constructors:
explicit Box(const T &val);
explicit Box(T &&val);
which is consistent with there being no implicit constructor from T to unique_ptr<T>.
from cxx.
in C++20, we have the option of making constructors conditionally explicit. This could be one path to take.explicit
means that doing something like
rust::String some_function () {
return { "hello" };
}
Will not compile. If you want these to be 'free-form', then it might stand to make them implicit.
That said, C++17's std::string
has added a constructor which is explicit and is for converting between any T
provided the following:
Implicitly converts t to a string view sv as if by std::basic_string_view<CharT, Traits> sv = t;, then initializes the string with the contents of sv, as if by basic_string(sv.data(), sv.size(), alloc). This overload only participates in overload resolution if std::is_convertible_v<const T&, std::basic_string_view<CharT, Traits>> is true and std::is_convertible_v<const T&, const CharT*> is false.
I will say that while some C++ committee folks are against implicit constructors, I tend to permit them for 'basic' types, even from other languages. (after all, if I return "hello"
from a C++ function that is being called by Python, it would stand to reason that I want it to be a python string, not a C char const*
).
That said, however, std::unique_ptr
has an explicit constructor for taking a single pointer, but make_unique
, and make_unique_for_overwrite
are provided to 'get around' this option. (However, this is because make_unique
is the default 'use new T(std::forward<Args>(args)...)
', while unique_ptr(pointer)
is provided to allow you to allocate from wherever. Since allocators aren't stabilized in Rust yet, it's not really an issue on that side of things, but it's something to keep in mind, I suppose. 🙂
from cxx.
Related Issues (20)
- Question: estimate workload to call functions from geogram HOT 1
- Returning `CxxString` from Rust to C++ HOT 5
- Extern C++ Enums HOT 5
- Advice/example on docs.rs strategy HOT 2
- Feature Request: Add support for nested Vector types HOT 1
- Building two CXX C++ bindings with the same symbols but in different namespaces. HOT 2
- Including bridge from another crate
- Error in configuring crates_universe when included as a Bazel module HOT 6
- Error compiling `cxx.cc` on Windows HOT 1
- Proposal: implementing native C++ std::error_code
- Link failure when using CXX-backed function from another crate HOT 1
- Unsupported element type of Vec<[u64; 3]>
- How to include C++ files whose directory is given by an environment variable? HOT 1
- Error compiling demo to wasm on macOS HOT 5
- Is there a way to expose a C++ class that is itself a wrapper on `std::shared_ptr`?
- How can I `include!` a file in OUT_DIR
- How can I return a vector of non-trivial type of C++ to Rust?
- LNK2019 unresolved symbol for Vec<SharedStruct> using MSVC
- Using CXX in multiple DLLs always results in undefined behavior?
- Does the core safety claim need rephrasing? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cxx.