89 Commits

Author SHA1 Message Date
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
David Tolnay
465305bdb4
Add rust::Vec<T>::empty 2020-04-25 18:02:13 -07:00
David Tolnay
7f2dc3bab0
Reorder rust::Vec below Box 2020-04-25 18:02:13 -07:00
David Tolnay
9c6bf2d8ef
Remove assumption of Vec field order 2020-04-25 18:02:12 -07:00
David Tolnay
a9a7ed18e6
Remove rust::Vec<T>::operator std::vector<T> 2020-04-25 18:02:08 -07:00
David Tolnay
507c2d75cf
Merge pull request #67 from myronahn/master
C++ std::vector<T> and Rust std::vec::Vec<T> support
2020-04-25 18:01:54 -07:00
David Tolnay
7c29546739
Revert some unrelated changes from PR 67 2020-04-25 13:13:43 -07:00
David Tolnay
37dd7e1174
Format with clang-format 2020-04-25 12:51:59 -07:00
Myron Ahn
eba35cfce7
C++ std::vector<T> and Rust std::vec::Vec<T> support
Add basic std::vector and std::vec::Vec support across FFI boundary.
2020-04-25 12:47:04 -07:00
David Tolnay
9706a5104c
Express Box const_pointer and pointer more concisely 2020-04-24 17:09:01 -07:00
David Tolnay
e710af1dd7
Fix typo in Slice repr comment 2020-04-14 16:42:06 -07:00
David Tolnay
efe81052e7
Touch up &[u8] PR 2020-04-14 16:42:06 -07:00