84 Commits (main)
 

Author SHA1 Message Date
pantonshire 7858cd68cf reference conversions for FmtWriteSink and IoWriteSink 2 years ago
pantonshire 706e8ca22a dedicated sink newtypes for fmt::Write and io::Write 2 years ago
pantonshire 3dcb61021f apply trait 2 years ago
pantonshire fc6caf0de6 iterator for Either 2 years ago
pantonshire 44e27e9d23 🩹 convert: remove `#[must_use]` from `result_elim` 3 years ago
pantonshire 266fa13165 sink: add `SinkString::empty` and `SinkString::with_capacity` 3 years ago
pantonshire e1e26c7fd5 🩹 Re-export `sink_fmt!` from `libshire::sink` module 3 years ago
pantonshire ba515d4cfc Add `FmtSink` trait and `sink_fmt!` macro 3 years ago
pantonshire ac26dc3422 ♻️ Rename `StringSink` to `SinkString` 3 years ago
pantonshire 8309e19a68 strings: remove wide pointer cast in CappedString impl
`CappedString::as_bytes` previously used a wide pointer cast to obtain a
`&[u8]` from the `[MaybeUninit<u8>; N]` buffer; it cast a `*const
[MaybeUninit<u8>]` to a `*const [u8]` as an intermediate step. Although
this seems to be valid and did not cause any UB detected by MIRI, it
seems to be generally accepted that `slice::from_raw_parts` is the
preferred way to transmute slices since it makes explicit the metadata
(length in this case) of the new wide pointer. This is in contrast to
casting with `as`, which implicitly copies the metadata from the old
wide pointer into the new one.

Therefore, this patch replaces the `as *const [u8]` conversion with a
call to `slice::from_raw_parts`.
3 years ago
pantonshire 7253d95010 strings: CappedString to FixedString conversion methods
This patch adds `CappedString::into_fixed` and
`CappedString::into_fixed_max_capacity` to allow for checked conversions
from `CappedString` to `FixedString`.
3 years ago
pantonshire 96daa5ca00 strings: refactor error types
This patch replaces the error type for `FixedString` and removes the
re-exports of the various string error types in the `strings` module.
3 years ago
pantonshire 352c01f613
Merge pull request #1 from pantonshire/capped-string
CappedString improvements
3 years ago
pantonshire cad45f5bce strings: unit tests and documentation for CappedString
This patch adds several unit tests for `CappedString`, which are
intended to be run under miri since `CappedString` uses lots of unsafe
code. It also adds documentation and documentation tests for a number of
previously undocumented `CappedString` methods.
3 years ago
pantonshire 383f0ae358 strings: add CappedString::clear method
This patch implements `CappedString::clear`, which provides an easy way
for users to clear the contents of a `CappedString`.
3 years ago
pantonshire 82034e14d0 strings: pointer-to-reference functions for InliningString
Previously, several functions in the implementation of `InliningString`
converted raw pointers to references as part of large blocks of code,
either via deref coercion or via `slice::from_raw_parts`. This created a
risk of Rust inferring reference lifetimes that were too long; this is
bad because it could result in a use-after-free or mutable aliasing.
This patch moves pointer-to-reference conversions in `InliningString` to
dedicated helper functions with explicit or easily-elided lifetimes to
avoid this issue.

This patch also introduces a
`InliningString::take_boxed_buf_invalidating` method, which provides a
way to move the boxed buffer out of an `InliningString` without aliasing
the box's heap allocation (which is not allowed). The `Drop`
implementation is reworked to use this method, as well as
`InliningString::into_boxed_str`.
3 years ago
pantonshire 119a32840a strings: fill in safety comments for CappedString
This patch fills in some missing safety comments in the implementation
of `CappedString`, and adds some additional comments for clarity.
3 years ago
pantonshire f411c30220 encoding: remove redundant pointer cast in url::percent_decode_utf8
A debug assertion in `encoding::url::percent_decode_utf8` previously
cast the result of `[u8]::as_ptr` to `*const u8`, which was redundant
because the return type of the `as_ptr` call was already `*const u8`.
This patch removes the redundant cast.
3 years ago
pantonshire 0d88775366 strings: implement push and push_truncating for CappedString
This patch implements the `CappedString::push` and
`CappedString::push_truncating` methods, which are like
`CappedString::push_str` and friends but take a single character rather
than a string slice.
3 years ago
pantonshire 2d5343681a strings: WIP CappedString::push_str and friends
This patch implements `CappedString::push_str` and its truncating
counterpart, `CappedString::push_str_truncating`. These methods provide
a safe API to append additional string data to the end of a
`CappedString`.

This is a work-in-progress and, like the rest of `CappedString`,
requires unit testing.
3 years ago
pantonshire c50b3c7daa strings: implement `CappedString::new` using `CappedString::from_raw_ptr`
This patch replaces the logic in `CappedString::new` for copying the
string data into a `[MaybeUninit<u8>]` buffer with a call to
`CappedString::from_raw_ptr`, which performs the same task.
3 years ago
pantonshire 4917be0963 strings: WIP CappedString refactoring and improvements
This patch changes the name of the CappedString error type to be more
descriptive, adds inline and must_use annotations to more public
functions, and begins implementing a wider variety of ways to create a
CappedString.
3 years ago
pantonshire 96a085686b test: improve test script to allow easily adding new runs
test.sh previously had each of its runs hard-coded; this patch changes
the script to loop over an array of cargo flags instead. This allows new
flags to be added to the array to easily add new runs to the test
script.
3 years ago
pantonshire c8783caae2 strings: CappedString now uses a MaybeUninit buf
CappedString was previously backed by a `[u8; N]`, which required
zeroing the buffer on creation. It now uses a `[MaybeUninit<u8>; N]`,
which does need to be zeroed. This should improve the performance of
creating a new CappedString, at the cost of slightly more unsafe code
required in its implementation.

Additionally, `as_bytes` and `as_bytes_mut` methods were introduced.
These are primarily used internally in the implementation of
CappedString, but are also provided as part of the public API to allow
users to do low-level operations on the underlying buffer backing the
CappedString. `as_bytes_mut` is unsafe, as this method can be used to
violate the UTF-8 property of the CappedString, which is undefined
behaviour.
3 years ago
pantonshire 5e612f153c Deny unsafe_op_in_unsafe_fn
The unsafe_op_in_unsafe_fn lint was previously set to allow, meaning
that unsafe function calls and operations were allowed within unsafe
functions without a surrounding unsafe block. This patch changes the
lint to deny, for the purpose of making unsafe operations in the
codebase more explicit.
3 years ago
pantonshire 299553bebf Documentation for CappedString 3 years ago
pantonshire d4c064c92e Conversions between CappedString and Box<str> 3 years ago
pantonshire ab9c62d993 Documentation 3 years ago
pantonshire 8f263e330a Optional decoding of plus character in percent encoded strings 3 years ago
pantonshire f0cc229a65 Percent decoding compliant with URL standard, export percent encoder and decoder types 3 years ago
pantonshire 2b27819104 Percent encode to String buffer 3 years ago
pantonshire d0ea531c05 RFC 3986 percent encoding, std feature now depends on alloc feature 3 years ago
pantonshire 5435784506 Make use of FixedString for hex encoding 3 years ago
pantonshire 8b605ca5c9 Fix for UUID 3 years ago
pantonshire 5535231475 Hex encoding functions now return arrays rather than tuples 3 years ago
Pantonshire 0e03fa87ba Fix doc tests for hex module 3 years ago
Pantonshire cf2648dde6 Seal the encoding::hex::Encode trait 3 years ago
Pantonshire eff2fab679 Encoding module 3 years ago
Pantonshire d1ca94954b impl Clone for InliningString 3 years ago
Pantonshire 5ca54944e8 Move the experimental InliningString to the inlining module 3 years ago
Pantonshire 6d6d35f2e0 More conversion functions for InliningString 3 years ago
Pantonshire f72b53e84f Improve test script 3 years ago
Pantonshire 8e733c444d Remove debugging info and use new serde::Deserialize impl for experimental InliningString 3 years ago
Pantonshire 45ae1c68eb Improved serde support 3 years ago
Pantonshire 0b4dbc6bc5 no_std support 3 years ago
Pantonshire 78b940ff19 Bash script for miri testing 3 years ago
Pantonshire c601e806dd Improve experimental InliningString documentation 3 years ago
Pantonshire b066273e66 Fixes to names and comments 3 years ago
Pantonshire 6bd8c8a111 Implement more traits for experimental InliningString 3 years ago
Pantonshire 821c75729d Experimental InliningString::empty, rename experimental ShString23 3 years ago