File tree Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ public:
2525 Str &operator=(const Str &) & noexcept;
2626
2727 explicit operator std::string() const;
28+ #if __cplusplus >= 201703L
29+ explicit operator std::string_view() const;
30+ #endif
2831
2932 // Note: no null terminator.
3033 const char *data() const noexcept;
Original file line number Diff line number Diff line change 99#include < iosfwd>
1010#include < iterator>
1111#include < new>
12- #if __cplusplus >= 202002L
13- #include < ranges>
14- #endif
1512#include < stdexcept>
1613#include < string>
1714#include < type_traits>
2320#include < sys/types.h>
2421#endif
2522
23+ #if __cplusplus >= 201703L
24+ #include < string_view>
25+ #endif
26+
27+ #if __cplusplus >= 202002L
28+ #include < ranges>
29+ #endif
30+
2631namespace rust {
2732inline namespace cxxbridge1 {
2833
@@ -123,6 +128,9 @@ class Str final {
123128 Str &operator =(const Str &) & noexcept = default ;
124129
125130 explicit operator std::string () const ;
131+ #if __cplusplus >= 201703L
132+ explicit operator std::string_view () const ;
133+ #endif
126134
127135 // Note: no null terminator.
128136 const char *data () const noexcept ;
Original file line number Diff line number Diff line change @@ -325,6 +325,12 @@ Str::operator std::string() const {
325325 return std::string (this ->data (), this ->size ());
326326}
327327
328+ #if __cplusplus >= 201703L
329+ Str::operator std::string_view () const {
330+ return std::string_view (this ->data (), this ->size ());
331+ }
332+ #endif
333+
328334const char *Str::data () const noexcept { return cxxbridge1$str$ptr (this ); }
329335
330336std::size_t Str::size () const noexcept { return cxxbridge1$str$len (this ); }
Original file line number Diff line number Diff line change @@ -874,6 +874,11 @@ extern "C" const char *cxx_run_test() noexcept {
874874 rust::Str out_param;
875875 r_return_str_via_out_param (Shared{2020 }, out_param);
876876 ASSERT (out_param == " 2020" );
877+
878+ #if __cplusplus >= 201703L
879+ std::string_view out_param_as_string_view{out_param};
880+ ASSERT (out_param_as_string_view == " 2020" );
881+ #endif
877882 }
878883
879884 rust::Str cstr = " test" ;
You can’t perform that action at this time.
0 commit comments