Commit Graph

76 Commits

Author SHA1 Message Date
YuhanLiin 9f45cc26c3 Make as_ptr and as_mut_ptr on ArrayString public 2024-03-07 21:06:22 +01:00
JakkuSakura 1cd7b9d859 feat: put len before xs 2024-03-07 21:05:54 +01:00
Elichai Turkel bb9279e2a6 Optionally implement Zeroize on ArrayVec/ArrayString 2023-06-13 22:03:50 +03:00
Kornel dc33f756d0 track_caller for capacity overflow panics 2023-04-10 22:45:30 +01:00
bluss 0e131fd781 Merge pull request #230 from msrd0/string-borrowmut
Add missing `BorrowMut` implementation for `ArrayString`
2022-11-12 10:04:16 +01:00
clubby789 c9ff579405 Fix stacked borrows violations
Use offsets from a single pointer instead of multiple pointers into an array.
Also removed an integer-pointer cast
2022-11-12 09:46:43 +01:00
Dominic 9dd3f3c67b Add missing BorrowMut for ArrayString 2022-11-09 17:08:42 +01:00
bluss a4690c9389 Merge pull request #194 from bhgomes/const-fns
Upgrade length/capacity-related functions to const-fn
2021-10-27 19:56:40 +02:00
bluss 1e74077b72 Doc/wording edit for zero_filled 2021-08-14 13:37:00 +02:00
Caio f5acafa0b3 Add zero_filled constructor 2021-08-13 20:04:44 -03:00
Brandon H. Gomes 17c5dd051e upgrade len/capacity-related functions to const-fn 2021-08-01 13:54:17 -04:00
Brandon H. Gomes 481f93084e add remaining_capacity to ArrayString 2021-08-01 13:53:21 -04:00
ltdk c4917813b8 Add ArrayString::as_mut_str 2021-06-20 15:35:54 -04:00
bluss 5685049fbe 0.7.0 2021-03-29 22:10:04 +02:00
bluss b7f3aa9fce FIX: Add new_const() for const construction and revert new to old version
The new() function is significantly faster, it optimizes better at the
moment/in current rust. For this reason, provide a const fn constructor,
but not as the default `new`.
2021-03-29 21:52:39 +02:00
rodrimati1992 5ad4687b1b Made ArrayVec::new and ArrayString::new const fns
Added utils module with a `MaybeUninit` helper type to construct `[MaybeUninit<T>; N]`

Removed all uses of the "unstable-const-fn" feature, and documented it as being deprecated.

Changed `assert_capacity_limit` macro to work in const contexts.
2021-03-28 14:48:27 -03:00
bluss 0c90469b61 FEAT: Use u32 for the length field in arrayvec
Store the length as u32 internally. This is to shrink the size of the
ArrayVec value (when possible, depending on element type).

Inline storage vectors larger than u32::MAX are very unlikely to be
useful - for these cases, prefer using Vec instead.

It's not possible to have the CAP type parameter be of type u32 (missing
features in const evaluation/const generics). We also have to panic at
runtime instead of having a static assertion for capacity, for similar
reasons.
2021-03-24 18:43:09 +01:00
bluss 6daae9ae68 FIX: Fix serde feature for const gen 2021-03-23 18:22:12 +01:00
bluss c9b095f263 FEAT: Port ArrayString to const generics 2021-03-23 18:22:12 +01:00
Caio 6dccb480f7 Impl TryFrom<fmt::Arguments<'a>> for ArrayString
Shortcut for

```
use fmt::Write;
let mut v = Self::new();
v.write_fmt(f).map_err(|e| CapacityError::new(e))?;
```
2020-12-09 20:21:03 -03:00
bluss 0acbba4ceb Merge pull request #165 from c410-f3r/try
impl TryFrom<&'a str> for ArrayString
2020-12-01 02:22:36 +01:00
bluss 50c9ed1abd Merge pull request #166 from hbina/use_add_instead_of_offset
Use `add` instead of `offset` so we don't need to cast to isize.
2020-10-23 18:13:41 +02:00
Hanif Bin Ariffin 92867bb118 Use add instead of offset to avoid casting to isize. 2020-10-21 20:50:00 +08:00
Caio 2267276dbb impl TryFrom<&'a str> for ArrayString 2020-08-28 08:16:20 -03:00
Mara Bos fe70c23e94 Add unstable-const-fn feature to make new() functions const. 2020-06-30 20:56:00 +02:00
nicbn 633c863b0a Add is_empty method for ArrayVec and ArrayString 2019-11-14 18:58:22 -03:00
bluss 090a5c50cb FIX: Support uninitalized data in encode_utf8, and update try_push
We were using &mut [u8] in encode_utf8, but this is not right according
to the developing unsafe coding guidelines. We need to use raw pointers
to write to possibly uninit memory.

We use a raw pointer form for encode_utf8. It was first attempted to
encapsulate the trusted-to-be-valid raw pointer in a simple { *mut u8,
usize } struct, but the current way of passing ptr and len separately
was the only way to not regress performance.

This impl maintains the same performance in arraystring benches.

Add exhaustive-style tests for encode_utf8
2019-10-09 12:23:44 +02:00
bluss f665142854 FEAT: Add ArrayString::len
This method is no new feature, but it saves us from going through deref
to str to fetch the length.
2019-10-09 12:21:25 +02:00
bluss 1483c6d372 FIX: Adjust (mostly remove) inline directives
Using the following principles:

- Trivial methods (empty and simple constants) can be inline(always)
- Generic methods don't need any inlining directive at all.
  ..with the exception of Deref which just seems to be extra important.
- Non-generic items use #[inline] to enable inlining at the
  compiler's discretion.
2019-10-09 10:02:20 +02:00
bluss cac792e633 API: Rename feature flag serde-1 to serde
(Old concerns don't matter anymore, especially with renamed deps.)
2019-09-25 14:34:08 +02:00
bluss e86a32d454 MAINT: Port to Rust 2018 edition 2019-09-02 22:07:30 +02:00
bluss f952e2c788 MAINT: Use ? operator instead of try!() macro 2019-09-02 22:06:20 +02:00
bluss 470cfd2a48 FIX: Update serde impls for Array changes 2019-09-01 14:48:14 +02:00
bluss 8093e8d886 FEAT: Switch to using MaybeUninit for everything
Use std::mem::MaybeUninit and stop using nodrop as a fallback.
This means we require Rust 1.36
2019-09-01 14:48:14 +02:00
bluss f2aad9f9a7 API: Update ArrayExt's methods to expose slices instead of pointers
This is a nicer and simpler interface to expose, since the ref to uninit
array to pointer cast is not usable anyway (it's historic now, arrayvec
itself does not use it anymore).
2019-09-01 14:47:44 +02:00
Aleksei Voronov 9207e7442f Implement FromStr for ArrayString
This is very useful for generic code that may want to parse arbitrary
input string into arbitrary other types.

Limitations of the FromStr trait don't allow us to keep the original string slice
inside the CapacityError, unfortunately.
2018-12-23 12:50:29 +01:00
bluss c4cd63209f FEAT: Use a separate union MaybeUninitCopy for ArrayString
This is the "real" union solution, and ArrayString can use it since its
backing array is Copy. Unfortunately, we'll have to use the Copy bound
on the type, making it "viral" and visible in the user API.
2018-12-16 18:32:14 +01:00
bluss 94ab27a649 Merge branch '0.4' of https://github.com/bluss/arrayvec into merge-0.4
* '0.4' of https://github.com/bluss/arrayvec:
  0.4.9
  TEST: Add test that ensures the MaybeUninit impl is used on nightly
  FIX: Remove use of uninitialized in ArrayString
  FEAT: Implement a "MaybeUninit" and use it conditionally
  TEST: Add test that Some(ArrayVec<[&_;_]>).is_some()
  MAINT: Test the 0.4 branch in travis
2018-12-16 18:09:20 +01:00
bluss d395a01e7c FIX: Remove use of uninitialized in ArrayString
We can't fix this properly (MaybeUninit with a union) until we change
the user visible API (we need to require that A: Copy.

As a temporary solution for arrayvec version 0.4.*, we use zeroed to
initialize an array of bytes, instead of using uninitialized. This may
have a negative performance impact, but the fix is to upgrade to future
arrayvec 0.5.
2018-12-15 15:12:03 +01:00
gnzlbg 9f57879028 fix undefined behavior in DerefMut of ArrayString 2018-08-31 22:43:05 +02:00
bluss a2e3fcea3f DOC: Minor fixes in docs, for ' → ’ 2017-10-27 22:54:46 +02:00
bluss 456aeaf557 FEAT: Remove odds dependency in arrayvec
Copy the encode_utf8 function from odds. std encode_utf8 requires Rust
1.15 and has a different signature, this one seems to fit us better.
2017-10-27 22:31:49 +02:00
bluss 895d450366 DOC: Promise debug assertions for unsafe methods
Instead of being vague about it, we can promise it.

We continue to be a bit vague in ArrayString::set_len.  I don't see how
to add a char boundary check in ArrayString::set_len unfortunately.

It's a tricky issue, checking char boundaries requires reading the
memory of the string, and we don't even know if the user of set_len has
initialized that area of memory yet (but they hopefully did).
2017-10-26 19:27:47 +02:00
Richard McCormack 187dd627e0 Add pop, truncate, and remove functions to ArrayString. Addresses #66 2017-10-26 12:57:14 -04:00
bluss ace20a9f43 DOC: Add docs for default values 2017-10-16 22:45:27 +02:00
bluss 9825e58061 FEAT: Add CapacityError::new 2017-09-24 18:07:12 +02:00
Tobias Bucher 9d0f801763 Add Default implementation for ArrayString
Fixes #67.
2017-09-11 19:59:06 +02:00
bluss 80d54a12ac DOC: Update ArrayString doc for push, push_str after 0.4 changes. 2017-09-11 19:44:15 +02:00
bluss f33c4e44dd DOC: Mention serde-1 feature 2017-09-11 19:43:54 +02:00
bluss 54457c7db9 DOC: Fix ArrayString docs for push/push_str 2017-08-08 21:07:02 +02:00