79 Commits

Author SHA1 Message Date
David Tolnay
c5629f021e
Support &mut [u8] 2020-11-24 13:45:27 -08:00
David Tolnay
2714d2c98f
Resolve modernize-use-override
https://github.com/dtolnay/cxx/issues/500
2020-11-23 18:17:45 -08:00
David Tolnay
79076c7b71
Resolve modernize-use-equals-default
https://github.com/dtolnay/cxx/issues/500
2020-11-23 18:17:01 -08:00
David Tolnay
1567186114
Resolve some instances of cppcoreguidelines-pro-type-member-init
https://github.com/dtolnay/cxx/issues/500
2020-11-23 18:14:34 -08:00
David Tolnay
733cd260f0
Remove deletion of Str(std::string &&) constructor 2020-11-21 11:57:59 -08:00
David Tolnay
0f0162f37d
Bump namespace to 1 2020-11-17 08:30:10 -08:00
David Tolnay
d9deed1186
Merge demo tweaks into master 2020-11-12 15:28:42 -08:00
David Tolnay
4e8c49ada4
Prefer typename consistently where supported by c++11 2020-11-11 15:53:23 -08:00
David Tolnay
ce29823968
Rename rust::Slice<T> to rust::Slice<const T> 2020-11-11 10:15:13 -08:00
David Tolnay
fb6b73c777
Add rust::Vec push_back and emplace_back 2020-11-10 20:08:14 -08:00
David Tolnay
a5a1301058
Provide rust::Fn call operator in generated header
Even though the generated code does not use them, this avoids a
situation where the user's code includes a generated header (but not
rust/cxx.h) and thus gets the class definition of rust::Fn, but with the
function call operators undefined. Previously they'd have gotten missing
template errors unless they also included rust/cxx.h.
2020-11-10 19:03:52 -08:00
David Tolnay
174bd95116
Expose way to bypass trivial destr/move on extern types passed by value 2020-11-02 10:23:52 -08:00
David Tolnay
36aa9e0bd8
Eliminate Slice<T>::Repr struct 2020-10-31 23:24:31 -07:00
David Tolnay
0356d33acb
Pass Str in PtrLen representation
MSVC is hesitant about passing private fields in an extern "C" signature.
Repro:

    struct Str1 {
      const char *ptr;
      size_t len;
    };

    struct Str2 {
    private:
      const char *ptr;
      size_t len;
    };

    extern "C" {
      Str1 str1();
      Str2 str2();
    }

Warning from MSVC v19.27:

    warning C4190: 'str2' has C-linkage specified, but returns UDT 'Str2' which is incompatible with C
2020-10-31 20:33:39 -07:00
David Tolnay
5b1ee1fc4e
Inline some Str accessors into the header 2020-10-31 18:21:39 -07:00
David Tolnay
2d7f117494
Make Str, Slice trivially copy assignable 2020-10-31 17:58:31 -07:00
David Tolnay
5df1f06eb8
Eliminate Str::Repr struct 2020-10-31 17:31:44 -07:00
David Tolnay
1549106cb0
Add move assignment operator for Error 2020-10-31 17:26:23 -07:00
David Tolnay
7c6ac7195e
Add copy assignment operator for Error 2020-10-31 17:24:32 -07:00
David Tolnay
84ddf9e27f
Move "impl" into anonymous namespace 2020-10-31 16:59:29 -07:00
David Tolnay
a0c9bc7167
Decouple Error from Str::Repr
It was misleading to use Str (which ordinarily represents borrowed
strings) also for owned error messages.
2020-10-31 16:59:29 -07:00
David Tolnay
4852122f35
Fill in some missing final specifiers 2020-10-31 14:59:42 -07:00
David Tolnay
de9a5b12b3
Guarantee trivial copy constructor and destructor for Str and Slice
Repro:

    const char *ptr(Str str) { return str.repr.ptr; }
    size_t len(Str str) { return str.repr.len; }

Before:

    ptr(Str):
        mov     rax, qword ptr [rdi]
        ret
    len(Str):
        mov     rax, qword ptr [rdi + 8]
        ret

After:

    ptr(Str):
        mov     rax, rdi
        ret
    len(Str):
        mov     rax, rsi
        ret
2020-10-31 12:17:42 -07:00
David Tolnay
cedcde1ddd
Fill in missing const on operator Repr 2020-10-31 11:47:14 -07:00
David Tolnay
8f16ae75f3
Bump namespace to 05 2020-10-08 19:34:50 -07:00
David Tolnay
da38b7c2a5
Update case of basetsd.h import to support cross compilation 2020-09-16 11:55:24 -04:00
David Tolnay
e4fa873f5f
Allow rust::Error to be caught as std::exception& 2020-09-08 15:04:56 -07:00
David Tolnay
38c8764d82
Add rust::slice and rust::vec lowercase aliases 2020-09-06 22:18:08 -07:00
David Tolnay
16ab146183
Fix missing panic template when using Vec
#277
2020-09-02 15:15:25 -07:00
David Tolnay
591dcb647d
Bump namespace to 04 2020-09-01 23:00:38 -07:00
David Tolnay
b10c4bc33a
Format with clang-format 10 2020-08-26 22:13:31 -07:00
David Tolnay
8e1e6ac25c
Extend exception message from Vec<T>::at 2020-08-26 22:13:31 -07:00
David Tolnay
521d99d093
Unify the way that String construction and Vec indexing throw 2020-08-26 21:50:11 -07:00
Stephen Crane
9e48d5b5c6 Add rust::Vec accessors
Adds operator[], at(), front(), and back() to rust::Vec.
2020-08-21 12:17:02 -07:00
David Tolnay
894c5e45dc
Add rust::Str(const char *, size_t) constructor 2020-07-29 18:21:50 -07:00
David Tolnay
c2bbd952d2
Add rust::String(const char *, size_t) constructor 2020-07-29 18:17:19 -07:00
David Tolnay
0ecd05a9bf
Include <new> when placement new is used 2020-07-29 16:32:03 -07:00
David Tolnay
2a2b9ad1f5
Move implementation details to the bottom of cxx.h 2020-05-12 20:43:20 -07:00
David Tolnay
1385ca42b2
Add missing noexcept on Vec<T>::const_iterator methods 2020-05-12 20:15:20 -07:00
David Tolnay
8c54eeca6c
Add missing noexcept on a Slice constructor 2020-05-12 20:08:20 -07:00
David Tolnay
74dd379f09
Format PR 157 with clang-format 2020-04-30 07:45:24 -07:00
David Tolnay
6960162922
Bump namespace to cxxbridge03 2020-04-29 18:49:50 -07:00
myronahn
da9be50ad8
Add all std::iterator_traits required types to const_iterator of rust::Vec<T> (#157)
https://en.cppreference.com/w/cpp/iterator/iterator_traits

`std::iterator_traits` requires the following 5 types:

- `difference_type` - a signed integer type that can be used to identify distance between iterators
- `value_type` - the type of the values that can be obtained by dereferencing the iterator. This type is void for output iterators.
- `pointer` - defines a pointer to the type iterated over (value_type)
- `reference` - defines a reference to the type iterated over (value_type)
- `iterator_category` - the category of the iterator. Must be one of iterator category tags.

The current `const_iterator` for `rust::Vec<T>` only defined `value_type` and `reference` which caused an error when using `std::copy` on gcc 7.5.0 on Ubuntu but seemed to work fine on MacOS.
2020-04-28 15:47:23 -07:00
David Tolnay
f97c2d51ed
Add construction and assignment for rust::Vec 2020-04-25 18:02:19 -07:00
David Tolnay
313b10ed1e
Add const bitcopy constructor for Vec 2020-04-25 18:02:19 -07:00
David Tolnay
c87c215f56
Add begin/end iterators to rust::Vec 2020-04-25 18:02:15 -07:00
David Tolnay
503d01902a
Add stride accessor for Vec
Will be required for implementing an iterator.
2020-04-25 18:02:15 -07:00
David Tolnay
219c0790d4
Generate data accessor for Vec 2020-04-25 18:02:15 -07:00
David Tolnay
cb80057051
Wire up Vec destructor 2020-04-25 18:02:14 -07:00
David Tolnay
0d3a7357fd
Remove unimplemented constructors from rust::Vec header 2020-04-25 18:02:14 -07:00