Fixed vendoring
Some checks failed
Continuous integration / Tests (push) Blocked by required conditions
Continuous integration / Tests (windows-latest) (push) Waiting to run
Continuous integration / Check clippy, formatting, and documentation (push) Failing after 20s
Continuous integration / Tests (ubuntu-latest) (push) Failing after 22s
Continuous integration / Check fuzzers (push) Failing after 18s
Continuous integration / Check mininum Rust version (push) Failing after 20s

This commit is contained in:
Сергей Конев 2024-10-16 15:19:37 +03:00
parent 3a69c90810
commit a8d83b9bab
8390 changed files with 829471 additions and 523234 deletions

View File

@ -1,2 +1,2 @@
tar: v@version@:.
tar: .
tar: ./vendor name=@name@-@version@-vendor base=vendor/

1003
Cargo.lock generated

File diff suppressed because it is too large Load Diff

1
vendor/adler2/.cargo-checksum.json vendored Normal file
View File

@ -0,0 +1 @@
{"files":{"CHANGELOG.md":"52435caf085b428cdb6171a34f4980f52aaaf541a3dced226c92eb82f69a48a7","Cargo.toml":"56b9cca6450964cbe772b6519bc048c2f56cc80e9261de1126d789c5e1951136","LICENSE-0BSD":"861399f8c21c042b110517e76dc6b63a2b334276c8cf17412fc3c8908ca8dc17","LICENSE-APACHE":"8ada45cd9f843acf64e4722ae262c622a2b3b3007c7310ef36ac1061a30f6adb","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"cd955d5d6a49161e6f7a04df4a5963581b66ed43fd5096b2dedca8e295efe4f9","RELEASE_PROCESS.md":"a86cd10fc70f167f8d00e9e4ce0c6b4ebdfa1865058390dffd1e0ad4d3e68d9d","benches/bench.rs":"d67bef1c7f36ed300a8fbcf9d50b9dfdead1fd340bf87a4d47d99a0c1c042c04","src/algo.rs":"932c2bc591d13fe4470185125617b5aaa660a3898f23b553acc85df0bf49dded","src/lib.rs":"4acd41668fe30daffa37084e7e223f268957b816afc1864ffb3f5d6d7adf0890"},"package":"512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"}

77
vendor/adler2/CHANGELOG.md vendored Normal file
View File

@ -0,0 +1,77 @@
# Changelog
All notable changes to this project will be documented in this file.
---
## [2.0.0](https://github.com/Frommi/miniz_oxide/compare/1.0.2..2.0.0) - 2024-08-04
First release of adler2 - fork of adler crate as the original is unmaintained and archived
##### Changes since last version of Adler:
### Bug Fixes
- **(core)** change to rust 2021 edition, update repository info and links, update author info - ([867b115](https://github.com/Frommi/miniz_oxide/commit/867b115bad79bf62098f2acccc81bf53ec5a125d)) - oyvindln
- **(core)** simplify some code and fix benches - ([128fb9c](https://github.com/Frommi/miniz_oxide/commit/128fb9cb6cad5c3a54fb0b6c68549d80b79a1fe0)) - oyvindln
### Changelog of original adler crate
---
## [1.0.2 - 2021-02-26](https://github.com/jonas-schievink/adler/releases/tag/v1.0.2)
- Fix doctest on big-endian systems ([#9]).
[#9]: https://github.com/jonas-schievink/adler/pull/9
## [1.0.1 - 2020-11-08](https://github.com/jonas-schievink/adler/releases/tag/v1.0.1)
### Fixes
- Fix documentation on docs.rs.
## [1.0.0 - 2020-11-08](https://github.com/jonas-schievink/adler/releases/tag/v1.0.0)
### Fixes
- Fix `cargo test --no-default-features` ([#5]).
### Improvements
- Extended and clarified documentation.
- Added more rustdoc examples.
- Extended CI to test the crate with `--no-default-features`.
### Breaking Changes
- `adler32_reader` now takes its generic argument by value instead of as a `&mut`.
- Renamed `adler32_reader` to `adler32`.
## [0.2.3 - 2020-07-11](https://github.com/jonas-schievink/adler/releases/tag/v0.2.3)
- Process 4 Bytes at a time, improving performance by up to 50% ([#2]).
## [0.2.2 - 2020-06-27](https://github.com/jonas-schievink/adler/releases/tag/v0.2.2)
- Bump MSRV to 1.31.0.
## [0.2.1 - 2020-06-27](https://github.com/jonas-schievink/adler/releases/tag/v0.2.1)
- Add a few `#[inline]` annotations to small functions.
- Fix CI badge.
- Allow integration into libstd.
## [0.2.0 - 2020-06-27](https://github.com/jonas-schievink/adler/releases/tag/v0.2.0)
- Support `#![no_std]` when using `default-features = false`.
- Improve performance by around 7x.
- Support Rust 1.8.0.
- Improve API naming.
## [0.1.0 - 2020-06-26](https://github.com/jonas-schievink/adler/releases/tag/v0.1.0)
Initial release.
[#2]: https://github.com/jonas-schievink/adler/pull/2
[#5]: https://github.com/jonas-schievink/adler/pull/5

97
vendor/adler2/Cargo.toml vendored Normal file
View File

@ -0,0 +1,97 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "adler2"
version = "2.0.0"
authors = [
"Jonas Schievink <jonasschievink@gmail.com>",
"oyvindln <oyvindln@users.noreply.github.com>",
]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "A simple clean-room implementation of the Adler-32 checksum"
documentation = "https://docs.rs/adler2/"
readme = "README.md"
keywords = [
"checksum",
"integrity",
"hash",
"adler32",
"zlib",
]
categories = ["algorithms"]
license = "0BSD OR MIT OR Apache-2.0"
repository = "https://github.com/oyvindln/adler2"
[package.metadata.docs.rs]
rustdoc-args = ["--cfg=docsrs"]
[package.metadata.release]
no-dev-version = true
pre-release-commit-message = "Release {{version}}"
tag-message = "{{version}}"
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
replace = """
## Unreleased
No changes.
## [{{version}} - {{date}}](https://github.com/jonas-schievink/adler/releases/tag/v{{version}})
"""
search = """
## Unreleased
"""
[[package.metadata.release.pre-release-replacements]]
file = "README.md"
replace = 'adler = "{{version}}"'
search = 'adler = "[a-z0-9\\.-]+"'
[[package.metadata.release.pre-release-replacements]]
file = "src/lib.rs"
replace = "https://docs.rs/adler/{{version}}"
search = 'https://docs.rs/adler/[a-z0-9\.-]+'
[lib]
name = "adler2"
path = "src/lib.rs"
[[bench]]
name = "bench"
path = "benches/bench.rs"
harness = false
[dependencies.compiler_builtins]
version = "0.1.2"
optional = true
[dependencies.core]
version = "1.0.0"
optional = true
package = "rustc-std-workspace-core"
[dev-dependencies.criterion]
version = "0.3.2"
[features]
default = ["std"]
rustc-dep-of-std = [
"core",
"compiler_builtins",
]
std = []

12
vendor/adler2/LICENSE-0BSD vendored Normal file
View File

@ -0,0 +1,12 @@
Copyright (C) Jonas Schievink <jonasschievink@gmail.com>
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

201
vendor/adler2/LICENSE-APACHE vendored Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
https://www.apache.org/licenses/LICENSE-2.0
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

46
vendor/adler2/README.md vendored Normal file
View File

@ -0,0 +1,46 @@
# Adler-32 checksums for Rust
This is a fork of the adler crate as the [original](https://github.com/jonas-schievink/adler) has been archived and is no longer updated by it's author
[![crates.io](https://img.shields.io/crates/v/adler.svg)](https://crates.io/crates/adler)
[![docs.rs](https://docs.rs/adler/badge.svg)](https://docs.rs/adler/)
![CI](https://github.com/jonas-schievink/adler/workflows/CI/badge.svg)
This crate provides a simple implementation of the Adler-32 checksum, used in
the zlib compression format.
Please refer to the [changelog](CHANGELOG.md) to see what changed in the last
releases.
## Features
- Permissively licensed (0BSD) clean-room implementation.
- Zero dependencies.
- Zero `unsafe`.
- Decent performance (3-4 GB/s) (see note).
- Supports `#![no_std]` (with `default-features = false`).
## Usage
Add an entry to your `Cargo.toml`:
```toml
[dependencies]
adler2 = "2.0.0"
```
Check the [API Documentation](https://docs.rs/adler/) for how to use the
crate's functionality.
## Rust version support
Currently, this crate supports all Rust versions starting at Rust 1.56.0.
Bumping the Minimum Supported Rust Version (MSRV) is *not* considered a breaking
change, but will not be done without good reasons. The latest 3 stable Rust
versions will always be supported no matter what.
## Performance
Due to the way the algorithm works this crate and the fact that it's not possible to use explicit simd in safe rust currently, this crate benefits drastically from being compiled with newer cpu instructions enabled (using e.g ```RUSTFLAGS=-C target-feature'+sse4.1``` or ```-C target-cpu=x86-64-v2```/```-C target-cpu=x86-64-v3``` arguments depending on what cpu support is being targeted.)
Judging by the crate benchmarks, on a Ryzen 5600, compiling with SSE 4.1 (enabled in x86-64-v2 feature level) enabled can give a ~50-150% speedup, enabling the LZCNT instruction (enabled in x86-64-v3 feature level) can give a further ~50% speedup,

13
vendor/adler2/RELEASE_PROCESS.md vendored Normal file
View File

@ -0,0 +1,13 @@
# What to do to publish a new release
1. Ensure all notable changes are in the changelog under "Unreleased".
2. Execute `cargo release <level>` to bump version(s), tag and publish
everything. External subcommand, must be installed with `cargo install
cargo-release`.
`<level>` can be one of `major|minor|patch`. If this is the first release
(`0.1.0`), use `minor`, since the version starts out as `0.0.0`.
3. Go to the GitHub releases, edit the just-pushed tag. Copy the release notes
from the changelog.

109
vendor/adler2/benches/bench.rs vendored Normal file
View File

@ -0,0 +1,109 @@
extern crate adler2;
extern crate criterion;
use adler2::{adler32_slice, Adler32};
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
fn simple(c: &mut Criterion) {
{
const SIZE: usize = 100;
let mut group = c.benchmark_group("simple-100b");
group.throughput(Throughput::Bytes(SIZE as u64));
group.bench_function("zeroes-100", |bencher| {
bencher.iter(|| {
adler32_slice(&[0; SIZE]);
});
});
group.bench_function("ones-100", |bencher| {
bencher.iter(|| {
adler32_slice(&[0xff; SIZE]);
});
});
}
{
const SIZE: usize = 1024;
let mut group = c.benchmark_group("simple-1k");
group.throughput(Throughput::Bytes(SIZE as u64));
group.bench_function("zeroes-1k", |bencher| {
bencher.iter(|| {
adler32_slice(&[0; SIZE]);
});
});
group.bench_function("ones-1k", |bencher| {
bencher.iter(|| {
adler32_slice(&[0xff; SIZE]);
});
});
}
{
const SIZE: usize = 1024 * 1024;
let mut group = c.benchmark_group("simple-1m");
group.throughput(Throughput::Bytes(SIZE as u64));
group.bench_function("zeroes-1m", |bencher| {
bencher.iter(|| {
adler32_slice(&[0; SIZE]);
});
});
group.bench_function("ones-1m", |bencher| {
bencher.iter(|| {
adler32_slice(&[0xff; SIZE]);
});
});
}
}
fn chunked(c: &mut Criterion) {
const SIZE: usize = 16 * 1024 * 1024;
let data = vec![0xAB; SIZE];
let mut group = c.benchmark_group("chunked-16m");
group.throughput(Throughput::Bytes(SIZE as u64));
group.bench_function("5552", |bencher| {
bencher.iter(|| {
let mut h = Adler32::new();
for chunk in data.chunks(5552) {
h.write_slice(chunk);
}
h.checksum()
});
});
group.bench_function("8k", |bencher| {
bencher.iter(|| {
let mut h = Adler32::new();
for chunk in data.chunks(8 * 1024) {
h.write_slice(chunk);
}
h.checksum()
});
});
group.bench_function("64k", |bencher| {
bencher.iter(|| {
let mut h = Adler32::new();
for chunk in data.chunks(64 * 1024) {
h.write_slice(chunk);
}
h.checksum()
});
});
group.bench_function("1m", |bencher| {
bencher.iter(|| {
let mut h = Adler32::new();
for chunk in data.chunks(1024 * 1024) {
h.write_slice(chunk);
}
h.checksum()
});
});
}
criterion_group!(benches, simple, chunked);
criterion_main!(benches);

155
vendor/adler2/src/algo.rs vendored Normal file
View File

@ -0,0 +1,155 @@
use crate::Adler32;
use std::ops::{AddAssign, MulAssign, RemAssign};
impl Adler32 {
pub(crate) fn compute(&mut self, bytes: &[u8]) {
// The basic algorithm is, for every byte:
// a = (a + byte) % MOD
// b = (b + a) % MOD
// where MOD = 65521.
//
// For efficiency, we can defer the `% MOD` operations as long as neither a nor b overflows:
// - Between calls to `write`, we ensure that a and b are always in range 0..MOD.
// - We use 32-bit arithmetic in this function.
// - Therefore, a and b must not increase by more than 2^32-MOD without performing a `% MOD`
// operation.
//
// According to Wikipedia, b is calculated as follows for non-incremental checksumming:
// b = n×D1 + (n1)×D2 + (n2)×D3 + ... + Dn + n*1 (mod 65521)
// Where n is the number of bytes and Di is the i-th Byte. We need to change this to account
// for the previous values of a and b, as well as treat every input Byte as being 255:
// b_inc = n×255 + (n-1)×255 + ... + 255 + n*65520
// Or in other words:
// b_inc = n*65520 + n(n+1)/2*255
// The max chunk size is thus the largest value of n so that b_inc <= 2^32-65521.
// 2^32-65521 = n*65520 + n(n+1)/2*255
// Plugging this into an equation solver since I can't math gives n = 5552.18..., so 5552.
//
// On top of the optimization outlined above, the algorithm can also be parallelized with a
// bit more work:
//
// Note that b is a linear combination of a vector of input bytes (D1, ..., Dn).
//
// If we fix some value k<N and rewrite indices 1, ..., N as
//
// 1_1, 1_2, ..., 1_k, 2_1, ..., 2_k, ..., (N/k)_k,
//
// then we can express a and b in terms of sums of smaller sequences kb and ka:
//
// ka(j) := D1_j + D2_j + ... + D(N/k)_j where j <= k
// kb(j) := (N/k)*D1_j + (N/k-1)*D2_j + ... + D(N/k)_j where j <= k
//
// a = ka(1) + ka(2) + ... + ka(k) + 1
// b = k*(kb(1) + kb(2) + ... + kb(k)) - 1*ka(2) - ... - (k-1)*ka(k) + N
//
// We use this insight to unroll the main loop and process k=4 bytes at a time.
// The resulting code is highly amenable to SIMD acceleration, although the immediate speedups
// stem from increased pipeline parallelism rather than auto-vectorization.
//
// This technique is described in-depth (here:)[https://software.intel.com/content/www/us/\
// en/develop/articles/fast-computation-of-fletcher-checksums.html]
const MOD: u32 = 65521;
const CHUNK_SIZE: usize = 5552 * 4;
let mut a = u32::from(self.a);
let mut b = u32::from(self.b);
let mut a_vec = U32X4([0; 4]);
let mut b_vec = a_vec;
let (bytes, remainder) = bytes.split_at(bytes.len() - bytes.len() % 4);
// iterate over 4 bytes at a time
let chunk_iter = bytes.chunks_exact(CHUNK_SIZE);
let remainder_chunk = chunk_iter.remainder();
for chunk in chunk_iter {
for byte_vec in chunk.chunks_exact(4) {
let val = U32X4::from(byte_vec);
a_vec += val;
b_vec += a_vec;
}
b += CHUNK_SIZE as u32 * a;
a_vec %= MOD;
b_vec %= MOD;
b %= MOD;
}
// special-case the final chunk because it may be shorter than the rest
for byte_vec in remainder_chunk.chunks_exact(4) {
let val = U32X4::from(byte_vec);
a_vec += val;
b_vec += a_vec;
}
b += remainder_chunk.len() as u32 * a;
a_vec %= MOD;
b_vec %= MOD;
b %= MOD;
// combine the sub-sum results into the main sum
b_vec *= 4;
b_vec.0[1] += MOD - a_vec.0[1];
b_vec.0[2] += (MOD - a_vec.0[2]) * 2;
b_vec.0[3] += (MOD - a_vec.0[3]) * 3;
for &av in a_vec.0.iter() {
a += av;
}
for &bv in b_vec.0.iter() {
b += bv;
}
// iterate over the remaining few bytes in serial
for &byte in remainder.iter() {
a += u32::from(byte);
b += a;
}
self.a = (a % MOD) as u16;
self.b = (b % MOD) as u16;
}
}
#[derive(Copy, Clone)]
struct U32X4([u32; 4]);
impl U32X4 {
#[inline]
fn from(bytes: &[u8]) -> Self {
U32X4([
u32::from(bytes[0]),
u32::from(bytes[1]),
u32::from(bytes[2]),
u32::from(bytes[3]),
])
}
}
impl AddAssign<Self> for U32X4 {
#[inline]
fn add_assign(&mut self, other: Self) {
// Implement this in a primitive manner to help out the compiler a bit.
self.0[0] += other.0[0];
self.0[1] += other.0[1];
self.0[2] += other.0[2];
self.0[3] += other.0[3];
}
}
impl RemAssign<u32> for U32X4 {
#[inline]
fn rem_assign(&mut self, quotient: u32) {
self.0[0] %= quotient;
self.0[1] %= quotient;
self.0[2] %= quotient;
self.0[3] %= quotient;
}
}
impl MulAssign<u32> for U32X4 {
#[inline]
fn mul_assign(&mut self, rhs: u32) {
self.0[0] *= rhs;
self.0[1] *= rhs;
self.0[2] *= rhs;
self.0[3] *= rhs;
}
}

287
vendor/adler2/src/lib.rs vendored Normal file
View File

@ -0,0 +1,287 @@
//! Adler-32 checksum implementation.
//!
//! This implementation features:
//!
//! - Permissively licensed (0BSD) clean-room implementation.
//! - Zero dependencies.
//! - Zero `unsafe`.
//! - Decent performance (3-4 GB/s).
//! - `#![no_std]` support (with `default-features = false`).
#![doc(html_root_url = "https://docs.rs/adler2/2.0.0")]
// Deny a few warnings in doctests, since rustdoc `allow`s many warnings by default
#![doc(test(attr(deny(unused_imports, unused_must_use))))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(missing_debug_implementations)]
#![forbid(unsafe_code)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(not(feature = "std"))]
extern crate core as std;
mod algo;
use std::hash::Hasher;
#[cfg(feature = "std")]
use std::io::{self, BufRead};
/// Adler-32 checksum calculator.
///
/// An instance of this type is equivalent to an Adler-32 checksum: It can be created in the default
/// state via [`new`] (or the provided `Default` impl), or from a precalculated checksum via
/// [`from_checksum`], and the currently stored checksum can be fetched via [`checksum`].
///
/// This type also implements `Hasher`, which makes it easy to calculate Adler-32 checksums of any
/// type that implements or derives `Hash`. This also allows using Adler-32 in a `HashMap`, although
/// that is not recommended (while every checksum is a hash function, they are not necessarily a
/// good one).
///
/// # Examples
///
/// Basic, piecewise checksum calculation:
///
/// ```
/// use adler2::Adler32;
///
/// let mut adler = Adler32::new();
///
/// adler.write_slice(&[0, 1, 2]);
/// adler.write_slice(&[3, 4, 5]);
///
/// assert_eq!(adler.checksum(), 0x00290010);
/// ```
///
/// Using `Hash` to process structures:
///
/// ```
/// use std::hash::Hash;
/// use adler2::Adler32;
///
/// #[derive(Hash)]
/// struct Data {
/// byte: u8,
/// word: u16,
/// big: u64,
/// }
///
/// let mut adler = Adler32::new();
///
/// let data = Data { byte: 0x1F, word: 0xABCD, big: !0 };
/// data.hash(&mut adler);
///
/// // hash value depends on architecture endianness
/// if cfg!(target_endian = "little") {
/// assert_eq!(adler.checksum(), 0x33410990);
/// }
/// if cfg!(target_endian = "big") {
/// assert_eq!(adler.checksum(), 0x331F0990);
/// }
///
/// ```
///
/// [`new`]: #method.new
/// [`from_checksum`]: #method.from_checksum
/// [`checksum`]: #method.checksum
#[derive(Debug, Copy, Clone)]
pub struct Adler32 {
a: u16,
b: u16,
}
impl Adler32 {
/// Creates a new Adler-32 instance with default state.
#[inline]
pub fn new() -> Self {
Self::default()
}
/// Creates an `Adler32` instance from a precomputed Adler-32 checksum.
///
/// This allows resuming checksum calculation without having to keep the `Adler32` instance
/// around.
///
/// # Example
///
/// ```
/// # use adler2::Adler32;
/// let parts = [
/// "rust",
/// "acean",
/// ];
/// let whole = adler2::adler32_slice(b"rustacean");
///
/// let mut sum = Adler32::new();
/// sum.write_slice(parts[0].as_bytes());
/// let partial = sum.checksum();
///
/// // ...later
///
/// let mut sum = Adler32::from_checksum(partial);
/// sum.write_slice(parts[1].as_bytes());
/// assert_eq!(sum.checksum(), whole);
/// ```
#[inline]
pub const fn from_checksum(sum: u32) -> Self {
Adler32 {
a: sum as u16,
b: (sum >> 16) as u16,
}
}
/// Returns the calculated checksum at this point in time.
#[inline]
pub fn checksum(&self) -> u32 {
(u32::from(self.b) << 16) | u32::from(self.a)
}
/// Adds `bytes` to the checksum calculation.
///
/// If efficiency matters, this should be called with Byte slices that contain at least a few
/// thousand Bytes.
pub fn write_slice(&mut self, bytes: &[u8]) {
self.compute(bytes);
}
}
impl Default for Adler32 {
#[inline]
fn default() -> Self {
Adler32 { a: 1, b: 0 }
}
}
impl Hasher for Adler32 {
#[inline]
fn finish(&self) -> u64 {
u64::from(self.checksum())
}
fn write(&mut self, bytes: &[u8]) {
self.write_slice(bytes);
}
}
/// Calculates the Adler-32 checksum of a byte slice.
///
/// This is a convenience function around the [`Adler32`] type.
///
/// [`Adler32`]: struct.Adler32.html
pub fn adler32_slice(data: &[u8]) -> u32 {
let mut h = Adler32::new();
h.write_slice(data);
h.checksum()
}
/// Calculates the Adler-32 checksum of a `BufRead`'s contents.
///
/// The passed `BufRead` implementor will be read until it reaches EOF (or until it reports an
/// error).
///
/// If you only have a `Read` implementor, you can wrap it in `std::io::BufReader` before calling
/// this function.
///
/// # Errors
///
/// Any error returned by the reader are bubbled up by this function.
///
/// # Examples
///
/// ```no_run
/// # fn run() -> Result<(), Box<dyn std::error::Error>> {
/// use adler2::adler32;
///
/// use std::fs::File;
/// use std::io::BufReader;
///
/// let file = File::open("input.txt")?;
/// let mut file = BufReader::new(file);
///
/// adler32(&mut file)?;
/// # Ok(()) }
/// # fn main() { run().unwrap() }
/// ```
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub fn adler32<R: BufRead>(mut reader: R) -> io::Result<u32> {
let mut h = Adler32::new();
loop {
let len = {
let buf = reader.fill_buf()?;
if buf.is_empty() {
return Ok(h.checksum());
}
h.write_slice(buf);
buf.len()
};
reader.consume(len);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn zeroes() {
assert_eq!(adler32_slice(&[]), 1);
assert_eq!(adler32_slice(&[0]), 1 | 1 << 16);
assert_eq!(adler32_slice(&[0, 0]), 1 | 2 << 16);
assert_eq!(adler32_slice(&[0; 100]), 0x00640001);
assert_eq!(adler32_slice(&[0; 1024]), 0x04000001);
assert_eq!(adler32_slice(&[0; 1024 * 1024]), 0x00f00001);
}
#[test]
fn ones() {
assert_eq!(adler32_slice(&[0xff; 1024]), 0x79a6fc2e);
assert_eq!(adler32_slice(&[0xff; 1024 * 1024]), 0x8e88ef11);
}
#[test]
fn mixed() {
assert_eq!(adler32_slice(&[1]), 2 | 2 << 16);
assert_eq!(adler32_slice(&[40]), 41 | 41 << 16);
assert_eq!(adler32_slice(&[0xA5; 1024 * 1024]), 0xd5009ab1);
}
/// Example calculation from https://en.wikipedia.org/wiki/Adler-32.
#[test]
fn wiki() {
assert_eq!(adler32_slice(b"Wikipedia"), 0x11E60398);
}
#[test]
fn resume() {
let mut adler = Adler32::new();
adler.write_slice(&[0xff; 1024]);
let partial = adler.checksum();
assert_eq!(partial, 0x79a6fc2e); // from above
adler.write_slice(&[0xff; 1024 * 1024 - 1024]);
assert_eq!(adler.checksum(), 0x8e88ef11); // from above
// Make sure that we can resume computing from the partial checksum via `from_checksum`.
let mut adler = Adler32::from_checksum(partial);
adler.write_slice(&[0xff; 1024 * 1024 - 1024]);
assert_eq!(adler.checksum(), 0x8e88ef11); // from above
}
#[cfg(feature = "std")]
#[test]
fn bufread() {
use std::io::BufReader;
fn test(data: &[u8], checksum: u32) {
// `BufReader` uses an 8 KB buffer, so this will test buffer refilling.
let mut buf = BufReader::new(data);
let real_sum = adler32(&mut buf).unwrap();
assert_eq!(checksum, real_sum);
}
test(&[], 1);
test(&[0; 1024], 0x04000001);
test(&[0; 1024 * 1024], 0x00f00001);
test(&[0xA5; 1024 * 1024], 0xd5009ab1);
}
}

View File

@ -1 +1 @@
{"files":{"COPYING":"01c266bced4a434da0051174d6bee16a4c82cf634e2679b6155d40d75012390f","Cargo.toml":"747d0fcb1257c9b8b013104da3c5a67f5d6cf8a95a2163b13703c01cab2c010a","DESIGN.md":"59c960e1b73b1d7fb41e4df6c0c1b1fcf44dd2ebc8a349597a7d0595f8cb5130","LICENSE-MIT":"0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f","README.md":"afc4d559a98cf190029af0bf320fc0022725e349cd2a303aac860254e28f3c53","UNLICENSE":"7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c","rustfmt.toml":"1ca600239a27401c4a43f363cf3f38183a212affc1f31bff3ae93234bbaec228","src/ahocorasick.rs":"c699c07df70be45c666e128509ad571a7649d2073e4ae16ac1efd6793c9c6890","src/automaton.rs":"22258a3e118672413119f8f543a9b912cce954e63524575c0ebfdf9011f9c2dd","src/dfa.rs":"bfef1a94c5e7410584b1beb4e857b40d1ae2031b881cbc06fb1300409bbd555f","src/lib.rs":"2a92d5c5e930f2d306508802e8a929135e1f41c9f5f8deda8f7eb98947179dd2","src/macros.rs":"c6c52ae05b24433cffaca7b78b3645d797862c5d5feffddf9f54909095ed6e05","src/nfa/contiguous.rs":"aeb6ee5fd80eea04decbc4b46aa27d1ab270b78d416a644da25b7934f009ee66","src/nfa/mod.rs":"ee7b3109774d14bbad5239c16bb980dd6b8185ec136d94fbaf2f0dc27d5ffa15","src/nfa/noncontiguous.rs":"de94f02b04efd8744fb096759a8897c22012b0e0ca3ace161fd87c71befefe04","src/packed/api.rs":"160d3b10823316f7b0924e13c3afd222c8a7db5c0a00432401f311ef27d6a1b7","src/packed/ext.rs":"66be06fde8558429da23a290584d4b9fae665bf64c2578db4fe5f5f3ee864869","src/packed/mod.rs":"0020cd6f07ba5c8955923a9516d7f758864260eda53a6b6f629131c45ddeec62","src/packed/pattern.rs":"1e3a289a730c141fc30b295811e372d046c6619c7fd670308299b889a06c7673","src/packed/rabinkarp.rs":"403146eb1d838a84601d171393542340513cd1ee7ff750f2372161dd47746586","src/packed/teddy/README.md":"3a43194b64e221543d885176aba3beb1224a927385a20eca842daf6b0ea2f342","src/packed/teddy/builder.rs":"720735ea6c7ff92b081426513e6e82feed24a922849297bb538d28f7b8129f81","src/packed/teddy/generic.rs":"ea252ab05b32cea7dd9d71e332071d243db7dd0362e049252a27e5881ba2bf39","src/packed/teddy/mod.rs":"17d741f7e2fb9dbac5ba7d1bd4542cf1e35e9f146ace728e23fe6bbed20028b2","src/packed/tests.rs":"8e2f56eb3890ed3876ecb47d3121996e416563127b6430110d7b516df3f83b4b","src/packed/vector.rs":"840065521cbd4701fa5b8b506d1537843d858c903f7cadf3c68749ea1780874b","src/tests.rs":"c68192ab97b6161d0d6ee96fefd80cc7d14e4486ddcd8d1f82b5c92432c24ed5","src/transducer.rs":"02daa33a5d6dac41dcfd67f51df7c0d4a91c5131c781fb54c4de3520c585a6e1","src/util/alphabet.rs":"6dc22658a38deddc0279892035b18870d4585069e35ba7c7e649a24509acfbcc","src/util/buffer.rs":"f9e37f662c46c6ecd734458dedbe76c3bb0e84a93b6b0117c0d4ad3042413891","src/util/byte_frequencies.rs":"2fb85b381c038c1e44ce94294531cdcd339dca48b1e61f41455666e802cbbc9e","src/util/debug.rs":"ab301ad59aa912529cb97233a54a05914dd3cb2ec43e6fec7334170b97ac5998","src/util/error.rs":"ecccd60e7406305023efcc6adcc826eeeb083ab8f7fbfe3d97469438cd4c4e5c","src/util/int.rs":"4ab6dbdba10027ddec2af63a9b28ce4eee30ded0daa5d8eb068b2b55542b6039","src/util/mod.rs":"7ab28d11323ecdbd982087f32eb8bceeee84f1a2583f3aae27039c36d58cf12c","src/util/prefilter.rs":"9fa4498f18bf70478b1996c1a013698b626d15f119aa81dbc536673c9f045718","src/util/primitives.rs":"f89f3fa1d8db4e37de9ca767c6d05e346404837cade6d063bba68972fafa610b","src/util/remapper.rs":"9f12d911583a325c11806eeceb46d0dfec863cfcfa241aed84d31af73da746e5","src/util/search.rs":"6af803e08b8b8c8a33db100623f1621b0d741616524ce40893d8316897f27ffe","src/util/special.rs":"7d2f9cb9dd9771f59816e829b2d96b1239996f32939ba98764e121696c52b146"},"package":"b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"}
{"files":{"COPYING":"01c266bced4a434da0051174d6bee16a4c82cf634e2679b6155d40d75012390f","Cargo.toml":"88c12a803c6c06c47cd9dabc8bcdba81f35d3bab637221d2106a86a543532731","DESIGN.md":"59c960e1b73b1d7fb41e4df6c0c1b1fcf44dd2ebc8a349597a7d0595f8cb5130","LICENSE-MIT":"0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f","README.md":"afc4d559a98cf190029af0bf320fc0022725e349cd2a303aac860254e28f3c53","UNLICENSE":"7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c","rustfmt.toml":"1ca600239a27401c4a43f363cf3f38183a212affc1f31bff3ae93234bbaec228","src/ahocorasick.rs":"c699c07df70be45c666e128509ad571a7649d2073e4ae16ac1efd6793c9c6890","src/automaton.rs":"22258a3e118672413119f8f543a9b912cce954e63524575c0ebfdf9011f9c2dd","src/dfa.rs":"bfef1a94c5e7410584b1beb4e857b40d1ae2031b881cbc06fb1300409bbd555f","src/lib.rs":"2a92d5c5e930f2d306508802e8a929135e1f41c9f5f8deda8f7eb98947179dd2","src/macros.rs":"c6c52ae05b24433cffaca7b78b3645d797862c5d5feffddf9f54909095ed6e05","src/nfa/contiguous.rs":"aeb6ee5fd80eea04decbc4b46aa27d1ab270b78d416a644da25b7934f009ee66","src/nfa/mod.rs":"ee7b3109774d14bbad5239c16bb980dd6b8185ec136d94fbaf2f0dc27d5ffa15","src/nfa/noncontiguous.rs":"de94f02b04efd8744fb096759a8897c22012b0e0ca3ace161fd87c71befefe04","src/packed/api.rs":"160d3b10823316f7b0924e13c3afd222c8a7db5c0a00432401f311ef27d6a1b7","src/packed/ext.rs":"66be06fde8558429da23a290584d4b9fae665bf64c2578db4fe5f5f3ee864869","src/packed/mod.rs":"0020cd6f07ba5c8955923a9516d7f758864260eda53a6b6f629131c45ddeec62","src/packed/pattern.rs":"1e3a289a730c141fc30b295811e372d046c6619c7fd670308299b889a06c7673","src/packed/rabinkarp.rs":"403146eb1d838a84601d171393542340513cd1ee7ff750f2372161dd47746586","src/packed/teddy/README.md":"3a43194b64e221543d885176aba3beb1224a927385a20eca842daf6b0ea2f342","src/packed/teddy/builder.rs":"08ec116a4a842a2bb1221d296a2515ef3672c54906bed588fb733364c07855d3","src/packed/teddy/generic.rs":"ea252ab05b32cea7dd9d71e332071d243db7dd0362e049252a27e5881ba2bf39","src/packed/teddy/mod.rs":"17d741f7e2fb9dbac5ba7d1bd4542cf1e35e9f146ace728e23fe6bbed20028b2","src/packed/tests.rs":"8e2f56eb3890ed3876ecb47d3121996e416563127b6430110d7b516df3f83b4b","src/packed/vector.rs":"70c325cfa6f7c5c4c9a6af7b133b75a29e65990a7fe0b9a4c4ce3c3d5a0fe587","src/tests.rs":"c68192ab97b6161d0d6ee96fefd80cc7d14e4486ddcd8d1f82b5c92432c24ed5","src/transducer.rs":"02daa33a5d6dac41dcfd67f51df7c0d4a91c5131c781fb54c4de3520c585a6e1","src/util/alphabet.rs":"6dc22658a38deddc0279892035b18870d4585069e35ba7c7e649a24509acfbcc","src/util/buffer.rs":"f9e37f662c46c6ecd734458dedbe76c3bb0e84a93b6b0117c0d4ad3042413891","src/util/byte_frequencies.rs":"2fb85b381c038c1e44ce94294531cdcd339dca48b1e61f41455666e802cbbc9e","src/util/debug.rs":"ab301ad59aa912529cb97233a54a05914dd3cb2ec43e6fec7334170b97ac5998","src/util/error.rs":"ecccd60e7406305023efcc6adcc826eeeb083ab8f7fbfe3d97469438cd4c4e5c","src/util/int.rs":"e264e6abebf5622b59f6500210773db36048371c4e509c930263334095959a52","src/util/mod.rs":"7ab28d11323ecdbd982087f32eb8bceeee84f1a2583f3aae27039c36d58cf12c","src/util/prefilter.rs":"9fa4498f18bf70478b1996c1a013698b626d15f119aa81dbc536673c9f045718","src/util/primitives.rs":"f89f3fa1d8db4e37de9ca767c6d05e346404837cade6d063bba68972fafa610b","src/util/remapper.rs":"9f12d911583a325c11806eeceb46d0dfec863cfcfa241aed84d31af73da746e5","src/util/search.rs":"6af803e08b8b8c8a33db100623f1621b0d741616524ce40893d8316897f27ffe","src/util/special.rs":"7d2f9cb9dd9771f59816e829b2d96b1239996f32939ba98764e121696c52b146"},"package":"8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"}

View File

@ -13,7 +13,7 @@
edition = "2021"
rust-version = "1.60.0"
name = "aho-corasick"
version = "1.1.2"
version = "1.1.3"
authors = ["Andrew Gallant <jamslam@gmail.com>"]
exclude = [
"/aho-corasick-debug",

View File

@ -230,7 +230,11 @@ impl Builder {
}
}
}
#[cfg(target_arch = "aarch64")]
#[cfg(all(
target_arch = "aarch64",
target_feature = "neon",
target_endian = "little"
))]
{
use self::aarch64::SlimNeon;
@ -301,7 +305,11 @@ impl Builder {
}
#[cfg(not(any(
all(target_arch = "x86_64", target_feature = "sse2"),
target_arch = "aarch64"
all(
target_arch = "aarch64",
target_feature = "neon",
target_endian = "little"
)
)))]
{
None
@ -705,7 +713,11 @@ mod x86_64 {
}
}
#[cfg(target_arch = "aarch64")]
#[cfg(all(
target_arch = "aarch64",
target_feature = "neon",
target_endian = "little"
))]
mod aarch64 {
use core::arch::aarch64::uint8x16_t;

View File

@ -89,6 +89,7 @@ pub(crate) trait Vector:
///
/// Callers must ensure that this is okay to call in the current target for
/// the current CPU.
#[allow(dead_code)] // unused, but useful enough to keep around?
unsafe fn or(self, vector2: Self) -> Self;
/// Shift each 8-bit lane in this vector to the right by the number of
@ -595,7 +596,11 @@ mod x86_64_avx2 {
}
}
#[cfg(target_arch = "aarch64")]
#[cfg(all(
target_arch = "aarch64",
target_feature = "neon",
target_endian = "little"
))]
mod aarch64_neon {
use core::arch::aarch64::*;

View File

@ -18,6 +18,10 @@ mode, then we would want to skip those when we know the conversions are always
non-lossy.
*/
// We define a little more than what we need, but I'd rather just have
// everything via a consistent and uniform API then have holes.
#![allow(dead_code)]
pub(crate) trait U8 {
fn as_usize(self) -> usize;
}
@ -272,13 +276,3 @@ impl<T> Pointer for *const T {
self as usize
}
}
pub(crate) trait PointerMut {
fn as_usize(self) -> usize;
}
impl<T> PointerMut for *mut T {
fn as_usize(self) -> usize {
self as usize
}
}

View File

@ -1 +1 @@
{"files":{"Cargo.lock":"23d8ed34328e75b81cc00af942f61b1bc05434435e92fca8a2d649abfc1b8f49","Cargo.toml":"ceca3cf1fc87f6ec6c2c687410fc2e60ed31bf58c39c54e8237603abc423b246","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"6efb0476a1cc085077ed49357026d8c173bf33017278ef440f222fb9cbcb66e6","README.md":"b230c2257d0c7a49b9bd97f2fa73abedcdc055757b5cedd2b0eb1a7a448ff461","benches/stream.rs":"7e666c4f4b79ddb5237361ed25264a966ee241192fbb2c1baea3006e3e0326b4","benches/strip.rs":"9603bd5ca1ae4661c2ccab50315dbfdec0c661ac2624262172bbd8f5d0bd87c9","benches/wincon.rs":"680e86933c008b242a3286c5149c33d3c086426eb99fe134b6e79f7578f96663","examples/dump-stream.rs":"9c5791bd739c3a74cfc24da90a5f96ee448b71ecf9800d3934028c5d3deb28e6","examples/query-stream.rs":"16f38843083174fbefa974a5aa38a5f3ffa51bd6e6db3dc1d91164462219399e","src/adapter/mod.rs":"baf4237ea0b18df63609e49d93572ca27c2202a4cbec0220adb5a7e815c7d8ed","src/adapter/strip.rs":"b324562426cb7ad8bceeeb8ea012746b5a046f901ea878d6de8d61f96ec96a55","src/adapter/wincon.rs":"96ce7d753abb4d6ed42c044545a4f557455bb825432904d6316c0aa245eb0085","src/auto.rs":"aa7f0988fc1c3f8c0d5bf1ff12e108cc3eb29d330f28da02cb4a2e09ec9fcc7c","src/buffer.rs":"83e7088b50dd3e2941c06a417d9eef75fda45311a2912ba94f480ec98d6f0183","src/fmt.rs":"cc11b005c4559843bd908a57958a13c8d0922fae6aff5261f3583c90e60da73c","src/lib.rs":"7502dcd2be531d787eac7efde761c95c892a425b55a53d6d99ef5d99d912a5f0","src/macros.rs":"a26ababe32a39732d0aade9674f6e5e267bd26c6ea06603ff9e61e80681195e0","src/stream.rs":"cbe8f61fba4c3c60934339c8bda5d1ff43320f57cdc4ed409aa173945a941b3d","src/strip.rs":"09c8bcd5bda0b07b56929026d965222d8129908f8386350b87314bc5fefcc2fe","src/wincon.rs":"e85c03ccfeca352a32572db8bb6c903f78c2003f5b375254edc5a69d6843728f"},"package":"d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"}
{"files":{"Cargo.lock":"b26d35c52b7411e23e1b269a20e42ba3ae059ffab6cd8bbac984259f4b5ff2a3","Cargo.toml":"eb44be751518aaaaeee4c93a72f34d90e5e758bf4a71e72debc21dc807c385f8","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"6efb0476a1cc085077ed49357026d8c173bf33017278ef440f222fb9cbcb66e6","README.md":"b230c2257d0c7a49b9bd97f2fa73abedcdc055757b5cedd2b0eb1a7a448ff461","benches/stream.rs":"ef40173fcda16b70e7ff5ef59615abb6eb529e991eaa6b899e027e62b2628891","benches/strip.rs":"b8bae0fbdac025f65a573a7d9209d2fbd17558f02f97d7beafd4b040d96ebb36","benches/wincon.rs":"4cafa0c5ef4e4c3344c36dcf57f1f2d77830499759e590e1960ef3eb8c1a6b2f","examples/dump-stream.rs":"6dbd8fca846ac8addd43ae941fa1220a7c31862896ac2ae4971afe792480523d","examples/query-stream.rs":"3796dec1ffe79cc49d088086eb27214764e8e0cff0370d60150aeecdadd47d30","src/adapter/mod.rs":"baf4237ea0b18df63609e49d93572ca27c2202a4cbec0220adb5a7e815c7d8ed","src/adapter/strip.rs":"f8638194008f5dd142f82c29dd8a4302ddc44891f3d17e186bdcb75e761ec55a","src/adapter/wincon.rs":"73eb62071a15908eb9d09aeccb0a4b50ad6259bfb367e496c42d48932b8fef10","src/auto.rs":"e513fd903153df148fe1718471db3363fb3ec6a3d7bc167426033ed37dd307ba","src/buffer.rs":"83e7088b50dd3e2941c06a417d9eef75fda45311a2912ba94f480ec98d6f0183","src/fmt.rs":"cc11b005c4559843bd908a57958a13c8d0922fae6aff5261f3583c90e60da73c","src/lib.rs":"b831a747cf3842ace5d7b1ca676758e79d043cf1416f548389d24dd480fe24ad","src/macros.rs":"a26ababe32a39732d0aade9674f6e5e267bd26c6ea06603ff9e61e80681195e0","src/stream.rs":"b2f430c5140c56f340efc1d4b8e7b9dfeef0bb0cf5ac27636167c1337be6aeb6","src/strip.rs":"155fa7bb0bc333b7648236df44d14ff742139c28659332bf03ed00b2943b8fac","src/wincon.rs":"e85c03ccfeca352a32572db8bb6c903f78c2003f5b375254edc5a69d6843728f"},"package":"64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"}

799
vendor/anstream/Cargo.lock generated vendored

File diff suppressed because it is too large Load Diff

View File

@ -11,9 +11,10 @@
[package]
edition = "2021"
rust-version = "1.70.0"
rust-version = "1.65.0"
name = "anstream"
version = "0.6.13"
version = "0.6.15"
build = false
include = [
"build.rs",
"src/**/*",
@ -24,6 +25,10 @@ include = [
"benches/**/*",
"examples/**/*",
]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "A simple cross platform library for writing colored text to a terminal."
homepage = "https://github.com/rust-cli/anstyle"
readme = "README.md"
@ -39,10 +44,7 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-cli/anstyle.git"
[package.metadata.docs.rs]
cargo-args = [
"-Zunstable-options",
"-Zrustdoc-scrape-examples",
]
all-features = true
rustdoc-args = [
"--cfg",
"docsrs",
@ -83,16 +85,33 @@ replace = """
[Unreleased]: https://github.com/rust-cli/anstyle/compare/{{tag_name}}...HEAD"""
search = "<!-- next-url -->"
[lib]
name = "anstream"
path = "src/lib.rs"
[[example]]
name = "dump-stream"
path = "examples/dump-stream.rs"
required-features = ["auto"]
[[example]]
name = "query-stream"
path = "examples/query-stream.rs"
required-features = ["auto"]
[[bench]]
name = "stream"
path = "benches/stream.rs"
harness = false
[[bench]]
name = "strip"
path = "benches/strip.rs"
harness = false
[[bench]]
name = "wincon"
harness = false
[[bench]]
name = "stream"
path = "benches/wincon.rs"
harness = false
[dependencies.anstyle]
@ -108,11 +127,14 @@ optional = true
[dependencies.colorchoice]
version = "1.0.0"
[dependencies.is_terminal_polyfill]
version = "1.48"
[dependencies.utf8parse]
version = "0.2.1"
[dev-dependencies.criterion]
version = "0.5.1"
[dev-dependencies.divan]
version = "0.1.11"
[dev-dependencies.lexopt]
version = "0.3.0"
@ -138,3 +160,73 @@ wincon = ["dep:anstyle-wincon"]
[target."cfg(windows)".dependencies.anstyle-wincon]
version = "3.0.1"
optional = true
[lints.clippy]
bool_assert_comparison = "allow"
branches_sharing_code = "allow"
checked_conversions = "warn"
collapsible_else_if = "allow"
create_dir = "warn"
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
doc_markdown = "warn"
empty_enum = "warn"
enum_glob_use = "warn"
expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
fallible_impl_from = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
float_cmp_const = "warn"
fn_params_excessive_bools = "warn"
from_iter_instead_of_collect = "warn"
if_same_then_else = "allow"
implicit_clone = "warn"
imprecise_flops = "warn"
inconsistent_struct_constructor = "warn"
inefficient_to_string = "warn"
infinite_loop = "warn"
invalid_upcast_comparisons = "warn"
items_after_statements = "warn"
large_digit_groups = "warn"
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
let_and_return = "allow"
linkedlist = "warn"
lossy_float_literal = "warn"
macro_use_imports = "warn"
match_wildcard_for_single_variants = "warn"
mem_forget = "warn"
mutex_integer = "warn"
needless_continue = "warn"
needless_for_each = "warn"
negative_feature_names = "warn"
path_buf_push_overwrite = "warn"
ptr_as_ptr = "warn"
rc_mutex = "warn"
redundant_feature_names = "warn"
ref_option_ref = "warn"
rest_pat_in_fully_bound_structs = "warn"
same_functions_in_if_condition = "warn"
self_named_module_files = "warn"
semicolon_if_nothing_returned = "warn"
single_match_else = "warn"
str_to_string = "warn"
string_add = "warn"
string_add_assign = "warn"
string_lit_as_bytes = "warn"
string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
verbose_file_reads = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
[lints.rust]
rust_2018_idioms = "warn"
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
unused_qualifications = "warn"

View File

@ -1,81 +1,104 @@
#![allow(clippy::unwrap_used)]
use std::io::Write as _;
use criterion::{black_box, Criterion};
fn stream(c: &mut Criterion) {
for (name, content) in [
("demo.vte", &include_bytes!("../tests/demo.vte")[..]),
("rg_help.vte", &include_bytes!("../tests/rg_help.vte")[..]),
("rg_linus.vte", &include_bytes!("../tests/rg_linus.vte")[..]),
(
"state_changes",
&b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\"[..],
),
] {
let mut group = c.benchmark_group(name);
group.bench_function("nop", |b| {
b.iter(|| {
let buffer = Vec::with_capacity(content.len());
#[divan::bench(args = DATA)]
fn nop(data: &Data) -> Vec<u8> {
let buffer = Vec::with_capacity(data.content().len());
let mut stream = buffer;
stream.write_all(content).unwrap();
stream.write_all(data.content()).unwrap();
black_box(stream)
})
});
group.bench_function("StripStream", |b| {
b.iter(|| {
let buffer = Vec::with_capacity(content.len());
stream
}
#[divan::bench(args = DATA)]
fn strip_stream(data: &Data) -> Vec<u8> {
let buffer = Vec::with_capacity(data.content().len());
let mut stream = anstream::StripStream::new(buffer);
stream.write_all(content).unwrap();
stream.write_all(data.content()).unwrap();
black_box(stream)
})
});
stream.into_inner()
}
#[divan::bench(args = DATA)]
#[cfg(all(windows, feature = "wincon"))]
group.bench_function("WinconStream", |b| {
b.iter(|| {
let buffer = Vec::with_capacity(content.len());
fn wincon_stream(data: &Data) -> Vec<u8> {
let buffer = Vec::with_capacity(data.content().len());
let mut stream = anstream::WinconStream::new(buffer);
stream.write_all(content).unwrap();
stream.write_all(data.content()).unwrap();
black_box(stream)
})
});
group.bench_function("AutoStream::always_ansi", |b| {
b.iter(|| {
let buffer = Vec::with_capacity(content.len());
stream.into_inner()
}
#[divan::bench(args = DATA)]
fn auto_stream_always_ansi(data: &Data) -> Vec<u8> {
let buffer = Vec::with_capacity(data.content().len());
let mut stream = anstream::AutoStream::always_ansi(buffer);
stream.write_all(content).unwrap();
stream.write_all(data.content()).unwrap();
black_box(stream)
})
});
group.bench_function("AutoStream::always", |b| {
b.iter(|| {
let buffer = Vec::with_capacity(content.len());
stream.into_inner()
}
#[divan::bench(args = DATA)]
fn auto_stream_always(data: &Data) -> Vec<u8> {
let buffer = Vec::with_capacity(data.content().len());
let mut stream = anstream::AutoStream::always(buffer);
stream.write_all(content).unwrap();
stream.write_all(data.content()).unwrap();
black_box(stream)
})
});
group.bench_function("AutoStream::never", |b| {
b.iter(|| {
let buffer = Vec::with_capacity(content.len());
stream.into_inner()
}
#[divan::bench(args = DATA)]
fn auto_stream_never(data: &Data) -> Vec<u8> {
let buffer = Vec::with_capacity(data.content().len());
let mut stream = anstream::AutoStream::never(buffer);
stream.write_all(content).unwrap();
stream.write_all(data.content()).unwrap();
black_box(stream)
})
});
stream.into_inner()
}
const DATA: &[Data] = &[
Data(
"0-state_changes",
b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\".as_slice(),
),
#[cfg(feature = "utf8")]
Data("1-demo.vte", include_bytes!("../tests/demo.vte").as_slice()),
Data(
"2-rg_help.vte",
include_bytes!("../tests/rg_help.vte").as_slice(),
),
Data(
"3-rg_linus.vte",
include_bytes!("../tests/rg_linus.vte").as_slice(),
),
];
#[derive(Debug)]
struct Data(&'static str, &'static [u8]);
impl Data {
const fn name(&self) -> &'static str {
self.0
}
const fn content(&self) -> &'static [u8] {
self.1
}
}
criterion::criterion_group!(benches, stream);
criterion::criterion_main!(benches);
impl std::fmt::Display for Data {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.name().fmt(f)
}
}
fn main() {
divan::main();
}

View File

@ -1,4 +1,4 @@
use criterion::{black_box, Criterion};
#![allow(clippy::unwrap_used)]
#[derive(Default)]
struct Strip(String);
@ -19,18 +19,99 @@ impl anstyle_parse::Perform for Strip {
}
}
fn strip(c: &mut Criterion) {
for (name, content) in [
("demo.vte", &include_bytes!("../tests/demo.vte")[..]),
("rg_help.vte", &include_bytes!("../tests/rg_help.vte")[..]),
("rg_linus.vte", &include_bytes!("../tests/rg_linus.vte")[..]),
(
"state_changes",
&b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\"[..],
#[divan::bench(args = DATA)]
fn advance_strip(data: &Data) -> String {
let mut stripped = Strip::with_capacity(data.content().len());
let mut parser = anstyle_parse::Parser::<anstyle_parse::DefaultCharAccumulator>::new();
for byte in data.content() {
parser.advance(&mut stripped, *byte);
}
stripped.0
}
#[divan::bench(args = DATA)]
fn strip_ansi_escapes(data: &Data) -> Vec<u8> {
let stripped = strip_ansi_escapes::strip(data.content());
stripped
}
#[divan::bench(args = DATA)]
fn strip_str(data: &Data) -> String {
if let Ok(content) = std::str::from_utf8(data.content()) {
let stripped = anstream::adapter::strip_str(content).to_string();
stripped
} else {
"".to_owned()
}
}
#[divan::bench(args = DATA)]
fn strip_str_strip_next(data: &Data) -> String {
if let Ok(content) = std::str::from_utf8(data.content()) {
let mut stripped = String::with_capacity(data.content().len());
let mut state = anstream::adapter::StripStr::new();
for printable in state.strip_next(content) {
stripped.push_str(printable);
}
stripped
} else {
"".to_owned()
}
}
#[divan::bench(args = DATA)]
fn strip_bytes(data: &Data) -> Vec<u8> {
let stripped = anstream::adapter::strip_bytes(data.content()).into_vec();
stripped
}
const DATA: &[Data] = &[
Data(
"0-state_changes",
b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\".as_slice(),
),
] {
#[cfg(feature = "utf8")]
Data("1-demo.vte", include_bytes!("../tests/demo.vte").as_slice()),
Data(
"2-rg_help.vte",
include_bytes!("../tests/rg_help.vte").as_slice(),
),
Data(
"3-rg_linus.vte",
include_bytes!("../tests/rg_linus.vte").as_slice(),
),
];
#[derive(Debug)]
struct Data(&'static str, &'static [u8]);
impl Data {
const fn name(&self) -> &'static str {
self.0
}
const fn content(&self) -> &'static [u8] {
self.1
}
}
impl std::fmt::Display for Data {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.name().fmt(f)
}
}
#[test]
fn verify_data() {
for data in DATA {
// Make sure the comparison is fair
if let Ok(content) = std::str::from_utf8(content) {
if let Ok(content) = std::str::from_utf8(data.content()) {
let mut stripped = Strip::with_capacity(content.len());
let mut parser = anstyle_parse::Parser::<anstyle_parse::DefaultCharAccumulator>::new();
for byte in content.as_bytes() {
@ -46,57 +127,9 @@ fn strip(c: &mut Criterion) {
.unwrap()
);
}
let mut group = c.benchmark_group(name);
group.bench_function("advance_strip", |b| {
b.iter(|| {
let mut stripped = Strip::with_capacity(content.len());
let mut parser =
anstyle_parse::Parser::<anstyle_parse::DefaultCharAccumulator>::new();
for byte in content {
parser.advance(&mut stripped, *byte);
}
black_box(stripped.0)
})
});
group.bench_function("strip_ansi_escapes", |b| {
b.iter(|| {
let stripped = strip_ansi_escapes::strip(content);
black_box(stripped)
})
});
if let Ok(content) = std::str::from_utf8(content) {
group.bench_function("strip_str", |b| {
b.iter(|| {
let stripped = anstream::adapter::strip_str(content).to_string();
black_box(stripped)
})
});
group.bench_function("StripStr", |b| {
b.iter(|| {
let mut stripped = String::with_capacity(content.len());
let mut state = anstream::adapter::StripStr::new();
for printable in state.strip_next(content) {
stripped.push_str(printable);
}
black_box(stripped)
})
});
}
group.bench_function("strip_bytes", |b| {
b.iter(|| {
let stripped = anstream::adapter::strip_bytes(content).into_vec();
black_box(stripped)
})
});
}
}
criterion::criterion_group!(benches, strip);
criterion::criterion_main!(benches);
fn main() {
divan::main();
}

View File

@ -1,26 +1,47 @@
use criterion::{black_box, Criterion};
fn wincon(c: &mut Criterion) {
for (name, content) in [
("demo.vte", &include_bytes!("../tests/demo.vte")[..]),
("rg_help.vte", &include_bytes!("../tests/rg_help.vte")[..]),
("rg_linus.vte", &include_bytes!("../tests/rg_linus.vte")[..]),
(
"state_changes",
&b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\"[..],
),
] {
let mut group = c.benchmark_group(name);
group.bench_function("wincon_bytes", |b| {
b.iter(|| {
#[divan::bench(args = DATA)]
fn nop(data: &Data) -> Vec<(anstyle::Style, String)> {
let mut state = anstream::adapter::WinconBytes::new();
let stripped = state.extract_next(content).collect::<Vec<_>>();
let stripped = state.extract_next(data.content()).collect::<Vec<_>>();
black_box(stripped)
})
});
stripped
}
const DATA: &[Data] = &[
Data(
"0-state_changes",
b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\".as_slice(),
),
#[cfg(feature = "utf8")]
Data("1-demo.vte", include_bytes!("../tests/demo.vte").as_slice()),
Data(
"2-rg_help.vte",
include_bytes!("../tests/rg_help.vte").as_slice(),
),
Data(
"3-rg_linus.vte",
include_bytes!("../tests/rg_linus.vte").as_slice(),
),
];
#[derive(Debug)]
struct Data(&'static str, &'static [u8]);
impl Data {
const fn name(&self) -> &'static str {
self.0
}
const fn content(&self) -> &'static [u8] {
self.1
}
}
criterion::criterion_group!(benches, wincon);
criterion::criterion_main!(benches);
impl std::fmt::Display for Data {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.name().fmt(f)
}
}
fn main() {
divan::main();
}

View File

@ -1,3 +1,5 @@
//! Write colored text, adapting to the terminals capabilities
use std::io::Write;
fn main() -> Result<(), lexopt::Error> {
@ -6,7 +8,9 @@ fn main() -> Result<(), lexopt::Error> {
let mut stdout = stdout.lock();
for fixed in 0..16 {
let color = anstyle::Ansi256Color(fixed).into_ansi().unwrap();
let color = anstyle::Ansi256Color(fixed)
.into_ansi()
.expect("within 4-bit color range");
let style = style(color, args.layer, args.effects);
let _ = print_number(&mut stdout, fixed, style);
if fixed == 7 || fixed == 15 {

View File

@ -1,3 +1,5 @@
//! Report a terminal's capabilities
fn main() {
println!("stdout:");
println!(

View File

@ -145,6 +145,7 @@ fn next_str<'s>(bytes: &mut &'s [u8], state: &mut State) -> Option<&'s str> {
#[inline]
unsafe fn from_utf8_unchecked<'b>(bytes: &'b [u8], safety_justification: &'static str) -> &'b str {
unsafe {
if cfg!(debug_assertions) {
// Catch problems more quickly when testing
std::str::from_utf8(bytes).expect(safety_justification)
@ -152,6 +153,7 @@ unsafe fn from_utf8_unchecked<'b>(bytes: &'b [u8], safety_justification: &'stati
std::str::from_utf8_unchecked(bytes)
}
}
}
#[inline]
fn is_utf8_continuation(b: u8) -> bool {
@ -327,7 +329,7 @@ fn next_bytes<'s>(
}
#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub struct Utf8Parser {
pub(crate) struct Utf8Parser {
utf8_parser: utf8parse::Parser,
}
@ -440,7 +442,7 @@ mod test {
fn test_strip_byte_multibyte() {
let bytes = [240, 145, 141, 139];
let expected = parser_strip(&bytes);
let actual = String::from_utf8(strip_byte(&bytes).to_vec()).unwrap();
let actual = String::from_utf8(strip_byte(&bytes).clone()).unwrap();
assert_eq!(expected, actual);
}
@ -456,7 +458,7 @@ mod test {
fn test_strip_byte_del() {
let bytes = [0x7f];
let expected = "";
let actual = String::from_utf8(strip_byte(&bytes).to_vec()).unwrap();
let actual = String::from_utf8(strip_byte(&bytes).clone()).unwrap();
assert_eq!(expected, actual);
}
@ -502,7 +504,7 @@ mod test {
dbg!(&s);
dbg!(s.as_bytes());
let expected = parser_strip(s.as_bytes());
let actual = String::from_utf8(strip_byte(s.as_bytes()).to_vec()).unwrap();
let actual = String::from_utf8(strip_byte(s.as_bytes()).clone()).unwrap();
assert_eq!(expected, actual);
}
}

View File

@ -150,7 +150,7 @@ impl anstyle_parse::Perform for WinconCapture {
break;
}
(State::Normal, 30..=37) => {
let color = to_ansi_color(value - 30).unwrap();
let color = to_ansi_color(value - 30).expect("within 4-bit range");
style = style.fg_color(Some(color.into()));
break;
}
@ -163,7 +163,7 @@ impl anstyle_parse::Perform for WinconCapture {
break;
}
(State::Normal, 40..=47) => {
let color = to_ansi_color(value - 40).unwrap();
let color = to_ansi_color(value - 40).expect("within 4-bit range");
style = style.bg_color(Some(color.into()));
break;
}
@ -180,12 +180,16 @@ impl anstyle_parse::Perform for WinconCapture {
state = State::PrepareCustomColor;
}
(State::Normal, 90..=97) => {
let color = to_ansi_color(value - 90).unwrap().bright(true);
let color = to_ansi_color(value - 90)
.expect("within 4-bit range")
.bright(true);
style = style.fg_color(Some(color.into()));
break;
}
(State::Normal, 100..=107) => {
let color = to_ansi_color(value - 100).unwrap().bright(true);
let color = to_ansi_color(value - 100)
.expect("within 4-bit range")
.bright(true);
style = style.bg_color(Some(color.into()));
break;
}

View File

@ -157,6 +157,7 @@ where
}
}
/// Returns `true` if the descriptor/handle refers to a terminal/tty.
#[inline]
pub fn is_terminal(&self) -> bool {
match &self.inner {

View File

@ -12,7 +12,6 @@
//!
//! Available styling crates:
//! - [anstyle](https://docs.rs/anstyle) for minimal runtime styling, designed to go in public APIs
//! (once it hits 1.0)
//! - [owo-colors](https://docs.rs/owo-colors) for feature-rich runtime styling
//! - [color-print](https://docs.rs/color-print) for feature-rich compile-time styling
//!
@ -33,6 +32,9 @@
//! And this will correctly handle piping to a file, etc
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
#![warn(clippy::print_stderr)]
#![warn(clippy::print_stdout)]
pub mod adapter;
pub mod stream;
@ -54,7 +56,9 @@ pub use wincon::WinconStream;
#[allow(deprecated)]
pub use buffer::Buffer;
/// An adaptive wrapper around the global standard output stream of the current process
pub type Stdout = AutoStream<std::io::Stdout>;
/// An adaptive wrapper around the global standard error stream of the current process
pub type Stderr = AutoStream<std::io::Stderr>;
/// Create an ANSI escape code compatible stdout

View File

@ -41,21 +41,23 @@ impl RawStream for crate::Buffer {}
#[allow(deprecated)]
impl RawStream for &'_ mut crate::Buffer {}
/// Trait to determine if a descriptor/handle refers to a terminal/tty.
pub trait IsTerminal: private::Sealed {
/// Returns `true` if the descriptor/handle refers to a terminal/tty.
fn is_terminal(&self) -> bool;
}
impl IsTerminal for std::io::Stdout {
#[inline]
fn is_terminal(&self) -> bool {
std::io::IsTerminal::is_terminal(self)
is_terminal_polyfill::IsTerminal::is_terminal(self)
}
}
impl IsTerminal for std::io::StdoutLock<'_> {
#[inline]
fn is_terminal(&self) -> bool {
std::io::IsTerminal::is_terminal(self)
is_terminal_polyfill::IsTerminal::is_terminal(self)
}
}
@ -69,14 +71,14 @@ impl IsTerminal for &'_ mut std::io::StdoutLock<'_> {
impl IsTerminal for std::io::Stderr {
#[inline]
fn is_terminal(&self) -> bool {
std::io::IsTerminal::is_terminal(self)
is_terminal_polyfill::IsTerminal::is_terminal(self)
}
}
impl IsTerminal for std::io::StderrLock<'_> {
#[inline]
fn is_terminal(&self) -> bool {
std::io::IsTerminal::is_terminal(self)
is_terminal_polyfill::IsTerminal::is_terminal(self)
}
}
@ -118,7 +120,7 @@ impl IsTerminal for &'_ mut Vec<u8> {
impl IsTerminal for std::fs::File {
#[inline]
fn is_terminal(&self) -> bool {
std::io::IsTerminal::is_terminal(self)
is_terminal_polyfill::IsTerminal::is_terminal(self)
}
}
@ -145,11 +147,14 @@ impl IsTerminal for &'_ mut crate::Buffer {
}
}
/// Lock a stream
pub trait AsLockedWrite: private::Sealed {
/// Locked writer type
type Write<'w>: RawStream + 'w
where
Self: 'w;
/// Lock a stream
fn as_locked_write(&mut self) -> Self::Write<'_>;
}

View File

@ -37,6 +37,7 @@ where
S: std::io::Write,
S: IsTerminal,
{
/// Returns `true` if the descriptor/handle refers to a terminal/tty.
#[inline]
pub fn is_terminal(&self) -> bool {
self.raw.is_terminal()

View File

@ -1 +1 @@
{"files":{"Cargo.lock":"7f68b5328c460caf1d2198b10fe1761e5f0282262f92d04076b30b25539970b0","Cargo.toml":"2834f39b7169c03b03da1e209f56133783ce00ea64d5f2c14381d93984ca20bf","LICENSE-APACHE":"b40930bbcf80744c86c46a12bc9da056641d722716c378f5659b9e555ef833e1","LICENSE-MIT":"c1d4bc00896473e0109ccb4c3c7d21addb55a4ff1a644be204dcfce26612af2a","README.md":"abc82171d436ee0eb221838e8d21a21a2e392504e87f0c130b5eca6a35671e1e","benches/parse.rs":"336c808d51c90db2497fa87e571df7f71c844a1b09be88839fe4255066c632f4","examples/parselog.rs":"58b7db739deed701aa0ab386d0d0c1772511b8aed1c08d31ec5b35a1c8cd4321","src/lib.rs":"c89f2afa0e982276dc47ca8d8a76d47516aa39aa9d3354254c87fdbf2f8ef4cc","src/params.rs":"8cfef4e2ab1961ca2d9f210da553fc6ac64bb6dbd03321f0ee7d6089ab45389c","src/state/codegen.rs":"8530124c8f998f391e47950f130590376321dcade810990f4312c3b1c0a61968","src/state/definitions.rs":"dc3dbb3244def74430a72b0108f019e22cc02e0ae5f563ee14d38300ff82b814","src/state/mod.rs":"be07c2ea393a971dd54117dc2ce8a3ffb5b803cb557ab468389b74570855fa37","src/state/table.rs":"673b7e9242c5248efc076086cc6923578ec2f059c0c26da21363528e20e4285c"},"package":"c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"}
{"files":{"Cargo.lock":"66fdd82ffad0fe31b3117f6d7763b7a7d05d148e36428730792ef5a48a397e6c","Cargo.toml":"d0872e29adfec0c5fe91d969182f94ead62f65767a8699ddf882b8249caa2ae2","LICENSE-APACHE":"b40930bbcf80744c86c46a12bc9da056641d722716c378f5659b9e555ef833e1","LICENSE-MIT":"c1d4bc00896473e0109ccb4c3c7d21addb55a4ff1a644be204dcfce26612af2a","README.md":"abc82171d436ee0eb221838e8d21a21a2e392504e87f0c130b5eca6a35671e1e","benches/parse.rs":"00747c503290b2e9171055861676e9037a555a8c968f58bade6c9411cee71e5f","examples/parselog.rs":"58b7db739deed701aa0ab386d0d0c1772511b8aed1c08d31ec5b35a1c8cd4321","src/lib.rs":"53d3cc122726aa2521141592a11cf56c08dfcb577ad89c7b9151fb75999a846a","src/params.rs":"8cfef4e2ab1961ca2d9f210da553fc6ac64bb6dbd03321f0ee7d6089ab45389c","src/state/codegen.rs":"503adaef236cf74d14bcb1b3b5166b168d7da96cf25102f8567f5074b7c9db1f","src/state/definitions.rs":"86433ae4901b2b647486c78fd74230d2963668d45e1d2df28b852d05610a2eff","src/state/mod.rs":"5c07420f7245b823bc1bcff797ae70c21cfdfaee8f326d37a6e95d529b08f38d","src/state/table.rs":"673b7e9242c5248efc076086cc6923578ec2f059c0c26da21363528e20e4285c"},"package":"eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"}

871
vendor/anstyle-parse/Cargo.lock generated vendored

File diff suppressed because it is too large Load Diff

View File

@ -11,9 +11,10 @@
[package]
edition = "2021"
rust-version = "1.70.0"
rust-version = "1.65.0"
name = "anstyle-parse"
version = "0.2.3"
version = "0.2.5"
build = false
include = [
"build.rs",
"src/**/*",
@ -24,6 +25,10 @@ include = [
"benches/**/*",
"examples/**/*",
]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Parse ANSI Style Escapes"
homepage = "https://github.com/rust-cli/anstyle"
readme = "README.md"
@ -37,6 +42,13 @@ categories = ["command-line-interface"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-cli/anstyle.git"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = [
"--cfg",
"docsrs",
]
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
min = 1
@ -72,9 +84,19 @@ replace = """
[Unreleased]: https://github.com/rust-cli/anstyle/compare/{{tag_name}}...HEAD"""
search = "<!-- next-url -->"
[lib]
name = "anstyle_parse"
path = "src/lib.rs"
[[example]]
name = "parselog"
path = "examples/parselog.rs"
[[bench]]
name = "parse"
path = "benches/parse.rs"
harness = false
required-features = ["utf8"]
[dependencies.arrayvec]
version = "0.7.2"
@ -89,15 +111,14 @@ optional = true
version = "3.0.1"
default-features = false
[dev-dependencies.criterion]
version = "0.5.1"
[dev-dependencies.divan]
version = "0.1.14"
[dev-dependencies.proptest]
version = "1.4.0"
[dev-dependencies.snapbox]
version = "0.4.14"
features = ["path"]
version = "0.6.5"
[dev-dependencies.vte_generate_state_changes]
version = "0.1.1"
@ -106,3 +127,73 @@ version = "0.1.1"
core = ["dep:arrayvec"]
default = ["utf8"]
utf8 = ["dep:utf8parse"]
[lints.clippy]
bool_assert_comparison = "allow"
branches_sharing_code = "allow"
checked_conversions = "warn"
collapsible_else_if = "allow"
create_dir = "warn"
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
doc_markdown = "warn"
empty_enum = "warn"
enum_glob_use = "warn"
expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
fallible_impl_from = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
float_cmp_const = "warn"
fn_params_excessive_bools = "warn"
from_iter_instead_of_collect = "warn"
if_same_then_else = "allow"
implicit_clone = "warn"
imprecise_flops = "warn"
inconsistent_struct_constructor = "warn"
inefficient_to_string = "warn"
infinite_loop = "warn"
invalid_upcast_comparisons = "warn"
items_after_statements = "warn"
large_digit_groups = "warn"
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
let_and_return = "allow"
linkedlist = "warn"
lossy_float_literal = "warn"
macro_use_imports = "warn"
match_wildcard_for_single_variants = "warn"
mem_forget = "warn"
mutex_integer = "warn"
needless_continue = "warn"
needless_for_each = "warn"
negative_feature_names = "warn"
path_buf_push_overwrite = "warn"
ptr_as_ptr = "warn"
rc_mutex = "warn"
redundant_feature_names = "warn"
ref_option_ref = "warn"
rest_pat_in_fully_bound_structs = "warn"
same_functions_in_if_condition = "warn"
self_named_module_files = "warn"
semicolon_if_nothing_returned = "warn"
single_match_else = "warn"
str_to_string = "warn"
string_add = "warn"
string_add_assign = "warn"
string_lit_as_bytes = "warn"
string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
verbose_file_reads = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
[lints.rust]
rust_2018_idioms = "warn"
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
unused_qualifications = "warn"

View File

@ -1,6 +1,56 @@
use criterion::{black_box, Criterion};
#![allow(clippy::incompatible_msrv)] // not verifying benches atm
use anstyle_parse::*;
use std::hint::black_box;
use anstyle_parse::DefaultCharAccumulator;
use anstyle_parse::Params;
use anstyle_parse::Parser;
use anstyle_parse::Perform;
#[divan::bench(args = DATA)]
fn advance(data: &Data) {
let mut dispatcher = BenchDispatcher;
let mut parser = Parser::<DefaultCharAccumulator>::new();
for byte in data.content() {
parser.advance(&mut dispatcher, *byte);
}
}
#[divan::bench(args = DATA)]
fn advance_strip(data: &Data) -> String {
let mut stripped = Strip::with_capacity(data.content().len());
let mut parser = Parser::<DefaultCharAccumulator>::new();
for byte in data.content() {
parser.advance(&mut stripped, *byte);
}
black_box(stripped.0)
}
#[divan::bench(args = DATA)]
fn state_change(data: &Data) {
let mut state = anstyle_parse::state::State::default();
for byte in data.content() {
let (next_state, action) = anstyle_parse::state::state_change(state, *byte);
state = next_state;
black_box(action);
}
}
#[divan::bench(args = DATA)]
fn state_change_strip_str(bencher: divan::Bencher<'_, '_>, data: &Data) {
if let Ok(content) = std::str::from_utf8(data.content()) {
bencher
.with_inputs(|| content)
.bench_local_values(|content| {
let stripped = strip_str(content);
black_box(stripped)
});
}
}
struct BenchDispatcher;
impl Perform for BenchDispatcher {
@ -96,20 +146,50 @@ fn strip_str(content: &str) -> String {
bytes = next;
}
#[allow(clippy::unwrap_used)]
String::from_utf8(stripped).unwrap()
}
fn parse(c: &mut Criterion) {
for (name, content) in [
#[cfg(feature = "utf8")]
("demo.vte", &include_bytes!("../tests/demo.vte")[..]),
("rg_help.vte", &include_bytes!("../tests/rg_help.vte")[..]),
("rg_linus.vte", &include_bytes!("../tests/rg_linus.vte")[..]),
(
"state_changes",
&b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\"[..],
const DATA: &[Data] = &[
Data(
"0-state_changes",
b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\".as_slice(),
),
] {
#[cfg(feature = "utf8")]
Data("1-demo.vte", include_bytes!("../tests/demo.vte").as_slice()),
Data(
"2-rg_help.vte",
include_bytes!("../tests/rg_help.vte").as_slice(),
),
Data(
"3-rg_linus.vte",
include_bytes!("../tests/rg_linus.vte").as_slice(),
),
];
#[derive(Debug)]
struct Data(&'static str, &'static [u8]);
impl Data {
const fn name(&self) -> &'static str {
self.0
}
const fn content(&self) -> &'static [u8] {
self.1
}
}
impl std::fmt::Display for Data {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.name().fmt(f)
}
}
#[test]
fn verify_data() {
for data in DATA {
let Data(name, content) = data;
// Make sure the comparison is fair
if let Ok(content) = std::str::from_utf8(content) {
let mut stripped = Strip::with_capacity(content.len());
@ -119,51 +199,9 @@ fn parse(c: &mut Criterion) {
}
assert_eq!(stripped.0, strip_str(content));
}
let mut group = c.benchmark_group(name);
group.bench_function("advance", |b| {
b.iter(|| {
let mut dispatcher = BenchDispatcher;
let mut parser = Parser::<DefaultCharAccumulator>::new();
for byte in content {
parser.advance(&mut dispatcher, *byte);
}
})
});
group.bench_function("advance_strip", |b| {
b.iter(|| {
let mut stripped = Strip::with_capacity(content.len());
let mut parser = Parser::<DefaultCharAccumulator>::new();
for byte in content {
parser.advance(&mut stripped, *byte);
}
black_box(stripped.0)
})
});
group.bench_function("state_change", |b| {
b.iter(|| {
let mut state = anstyle_parse::state::State::default();
for byte in content {
let (next_state, action) = anstyle_parse::state::state_change(state, *byte);
state = next_state;
black_box(action);
}
})
});
if let Ok(content) = std::str::from_utf8(content) {
group.bench_function("state_change_strip_str", |b| {
b.iter(|| {
let stripped = strip_str(content);
black_box(stripped)
})
});
}
}
}
criterion::criterion_group!(benches, parse);
criterion::criterion_main!(benches);
fn main() {
divan::main();
}

View File

@ -29,6 +29,10 @@
//!
//! [Paul Williams' ANSI parser state machine]: https://vt100.net/emu/dec_ansi_parser
#![cfg_attr(not(test), no_std)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![allow(missing_docs)]
#![warn(clippy::print_stderr)]
#![warn(clippy::print_stdout)]
#[cfg(not(feature = "core"))]
extern crate alloc;
@ -53,6 +57,7 @@ const MAX_OSC_PARAMS: usize = 16;
const MAX_OSC_RAW: usize = 1024;
/// Parser for raw _VTE_ protocol which delegates actions to a [`Perform`]
#[allow(unused_qualifications)]
#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub struct Parser<C = DefaultCharAccumulator> {
state: State,
@ -162,9 +167,9 @@ where
}
}
/// Separate method for osc_dispatch that borrows self as read-only
/// Separate method for `osc_dispatch` that borrows self as read-only
///
/// The aliasing is needed here for multiple slices into self.osc_raw
/// The aliasing is needed here for multiple slices into `self.osc_raw`
#[inline]
fn osc_dispatch<P: Perform>(&self, performer: &mut P, byte: u8) {
let mut slices: [MaybeUninit<&[u8]>; MAX_OSC_PARAMS] =
@ -322,12 +327,14 @@ pub trait CharAccumulator: Default {
fn add(&mut self, byte: u8) -> Option<char>;
}
/// Most flexible [`CharAccumulator`] for [`Parser`] based on active features
#[cfg(feature = "utf8")]
pub type DefaultCharAccumulator = Utf8Parser;
#[cfg(not(feature = "utf8"))]
pub type DefaultCharAccumulator = AsciiParser;
/// Only allow parsing 7-bit ASCII
#[allow(clippy::exhaustive_structs)]
#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub struct AsciiParser;

View File

@ -1,5 +1,6 @@
use super::{pack, unpack, Action, State};
use snapbox::file;
use vte_generate_state_changes::generate_state_changes;
#[test]
@ -9,7 +10,7 @@ fn table() {
let content = String::from_utf8(content).unwrap();
let content = codegenrs::rustfmt(&content, None).unwrap();
snapbox::assert_eq_path("./src/state/table.rs", content);
snapbox::assert_data_eq!(content, file!["table.rs"].raw());
}
#[allow(clippy::write_literal)]
@ -17,7 +18,7 @@ fn generate_table(file: &mut impl std::io::Write) -> std::io::Result<()> {
writeln!(
file,
"// This file is @generated by {}",
file!().replace('\\', "/")
std::file!().replace('\\', "/")
)?;
writeln!(file)?;
writeln!(
@ -51,7 +52,7 @@ pub(crate) const STATE_CHANGES: [[u8; 256]; 16] = ["#
/// This is the state change table. It's indexed first by current state and then by the next
/// character in the pty stream.
pub static STATE_CHANGES: [[u8; 256]; 16] = state_changes();
pub(crate) static STATE_CHANGES: [[u8; 256]; 16] = state_changes();
generate_state_changes!(state_changes, {
Anywhere {
0x18 => (Ground, Execute),

View File

@ -1,3 +1,5 @@
#![allow(clippy::exhaustive_enums)]
use core::mem;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@ -110,20 +112,20 @@ const ACTIONS: [Action; 16] = [
///
/// Bad things will happen if those invariants are violated.
#[inline(always)]
pub const fn unpack(delta: u8) -> (State, Action) {
pub(crate) const fn unpack(delta: u8) -> (State, Action) {
unsafe {
(
// State is stored in bottom 4 bits
mem::transmute(delta & 0x0f),
mem::transmute::<u8, State>(delta & 0x0f),
// Action is stored in top 4 bits
mem::transmute(delta >> 4),
mem::transmute::<u8, Action>(delta >> 4),
)
}
}
#[inline(always)]
#[cfg(test)]
pub const fn pack(state: State, action: Action) -> u8 {
pub(crate) const fn pack(state: State, action: Action) -> u8 {
(action as u8) << 4 | state as u8
}

View File

@ -1,3 +1,5 @@
//! ANSI escape code parsing state machine
#[cfg(test)]
mod codegen;
mod definitions;

View File

@ -1 +1 @@
{"files":{"Cargo.lock":"dbef8401bf3e334d4f3a8230f2506dbc1439dd3aea07cbbc174125eb5fef0eed","Cargo.toml":"4b85a1d05db43bc0aa4ccc814c9e6b922d6a811aa79e02e614f5baccfa803a05","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"6efb0476a1cc085077ed49357026d8c173bf33017278ef440f222fb9cbcb66e6","README.md":"94cda3914d2693b89e0b5855ffff04b971823f6cbae885a1610353254a269ed9","examples/query.rs":"d9f5b94967c7b9579ee399c481148b07fd0fb371f4a5d557017ff86cb5034543","src/lib.rs":"4dd716dbe701acc5644b25d84503d53ea8bc8fb9bf81914b2183526edc63826c","src/windows.rs":"44272f13079fbaed8c16426950c24d9de94d81eba0636138d8e44346eccc0acd"},"package":"e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"}
{"files":{"Cargo.lock":"45ed6f11e8435d138910e4f6c592f3474095aef167645136cafde3bea8e14924","Cargo.toml":"ffc6613f53980ffb99ee42a70e75394900a79c2c346ec5e4cdb77693f4ea59f2","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"6efb0476a1cc085077ed49357026d8c173bf33017278ef440f222fb9cbcb66e6","README.md":"94cda3914d2693b89e0b5855ffff04b971823f6cbae885a1610353254a269ed9","examples/query.rs":"fca5f5f48a20d282982a4de584dd79470375d89bf990447b0c6f24e842956297","src/lib.rs":"4ac6f0b05badc4a3b6835fbe03a667e74f1f30e32f83770340e5ba43fdc2744c","src/windows.rs":"e3a0e396d5a092cd5b775f03c64af698bb407ef9a157f0e94df29668c543a9ba"},"package":"6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"}

41
vendor/anstyle-query/Cargo.lock generated vendored
View File

@ -4,7 +4,7 @@ version = 3
[[package]]
name = "anstyle-query"
version = "1.0.2"
version = "1.1.1"
dependencies = [
"windows-sys",
]
@ -20,13 +20,14 @@ dependencies = [
[[package]]
name = "windows-targets"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
@ -35,42 +36,48 @@ dependencies = [
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]]
name = "windows_i686_gnu"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
[[package]]
name = "windows_i686_msvc"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"

View File

@ -11,9 +11,10 @@
[package]
edition = "2021"
rust-version = "1.70.0"
rust-version = "1.65.0"
name = "anstyle-query"
version = "1.0.2"
version = "1.1.1"
build = false
include = [
"build.rs",
"src/**/*",
@ -24,6 +25,10 @@ include = [
"benches/**/*",
"examples/**/*",
]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Look up colored console capabilities"
readme = "README.md"
keywords = [
@ -37,6 +42,13 @@ categories = ["command-line-interface"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-cli/anstyle"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = [
"--cfg",
"docsrs",
]
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
min = 1
@ -72,9 +84,87 @@ replace = """
[Unreleased]: https://github.com/rust-cli/anstyle/compare/{{tag_name}}...HEAD"""
search = "<!-- next-url -->"
[lib]
name = "anstyle_query"
path = "src/lib.rs"
[[example]]
name = "query"
path = "examples/query.rs"
[target."cfg(windows)".dependencies.windows-sys]
version = "0.52.0"
features = [
"Win32_System_Console",
"Win32_Foundation",
]
[lints.clippy]
bool_assert_comparison = "allow"
branches_sharing_code = "allow"
checked_conversions = "warn"
collapsible_else_if = "allow"
create_dir = "warn"
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
doc_markdown = "warn"
empty_enum = "warn"
enum_glob_use = "warn"
expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
fallible_impl_from = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
float_cmp_const = "warn"
fn_params_excessive_bools = "warn"
from_iter_instead_of_collect = "warn"
if_same_then_else = "allow"
implicit_clone = "warn"
imprecise_flops = "warn"
inconsistent_struct_constructor = "warn"
inefficient_to_string = "warn"
infinite_loop = "warn"
invalid_upcast_comparisons = "warn"
items_after_statements = "warn"
large_digit_groups = "warn"
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
let_and_return = "allow"
linkedlist = "warn"
lossy_float_literal = "warn"
macro_use_imports = "warn"
match_wildcard_for_single_variants = "warn"
mem_forget = "warn"
mutex_integer = "warn"
needless_continue = "warn"
needless_for_each = "warn"
negative_feature_names = "warn"
path_buf_push_overwrite = "warn"
ptr_as_ptr = "warn"
rc_mutex = "warn"
redundant_feature_names = "warn"
ref_option_ref = "warn"
rest_pat_in_fully_bound_structs = "warn"
same_functions_in_if_condition = "warn"
self_named_module_files = "warn"
semicolon_if_nothing_returned = "warn"
single_match_else = "warn"
str_to_string = "warn"
string_add = "warn"
string_add_assign = "warn"
string_lit_as_bytes = "warn"
string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
verbose_file_reads = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
[lints.rust]
rust_2018_idioms = "warn"
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
unused_qualifications = "warn"

View File

@ -1,3 +1,5 @@
//! Report a terminal's capabilities
fn main() {
println!("clicolor: {:?}", anstyle_query::clicolor());
println!("clicolor_force: {}", anstyle_query::clicolor_force());

View File

@ -1,3 +1,10 @@
//! Low level terminal capability lookups
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
#![warn(clippy::print_stderr)]
#![warn(clippy::print_stdout)]
pub mod windows;
/// Check [CLICOLOR] status
@ -25,11 +32,7 @@ pub fn clicolor() -> Option<bool> {
/// [CLICOLOR_FORCE]: https://bixense.com/clicolors/
#[inline]
pub fn clicolor_force() -> bool {
let value = std::env::var_os("CLICOLOR_FORCE");
value
.as_deref()
.unwrap_or_else(|| std::ffi::OsStr::new("0"))
!= "0"
non_empty(std::env::var_os("CLICOLOR_FORCE").as_deref())
}
/// Check [NO_COLOR] status
@ -44,8 +47,7 @@ pub fn clicolor_force() -> bool {
/// [NO_COLOR]: https://no-color.org/
#[inline]
pub fn no_color() -> bool {
let value = std::env::var_os("NO_COLOR");
value.as_deref().unwrap_or_else(|| std::ffi::OsStr::new("")) != ""
non_empty(std::env::var_os("NO_COLOR").as_deref())
}
/// Check `TERM` for color support
@ -132,3 +134,27 @@ pub fn is_ci() -> bool {
// - Woodpecker sets it to `woodpecker`
std::env::var_os("CI").is_some()
}
fn non_empty(var: Option<&std::ffi::OsStr>) -> bool {
!var.unwrap_or_default().is_empty()
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn non_empty_not_present() {
assert!(!non_empty(None));
}
#[test]
fn non_empty_empty() {
assert!(!non_empty(Some(std::ffi::OsStr::new(""))));
}
#[test]
fn non_empty_texty() {
assert!(non_empty(Some(std::ffi::OsStr::new("hello"))));
}
}

View File

@ -64,7 +64,7 @@ mod windows_console {
}
}
/// Enable ANSI escape codes (ENABLE_VIRTUAL_TERMINAL_PROCESSING)
/// Enable ANSI escape codes ([`ENABLE_VIRTUAL_TERMINAL_PROCESSING`](https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#output-sequences))
///
/// For non-windows systems, returns `None`
pub fn enable_ansi_colors() -> Option<bool> {

View File

@ -1 +1 @@
{"files":{"Cargo.lock":"3cc0f5705ebb0bb446d6f88f71832d2db70bee8c78a545343a755e2a969212a3","Cargo.toml":"5a090b294286cb22bed379e818f8657da219f62fe0e1e8eb21e91aaaf875c139","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"73b0d84e4b954ce904a00043379767ae2a5f8d4f40564639cee230f639fe4dae","README.md":"513a578c6c2ea39a811e2038358e512cbc0c709e3a7c18303871ec2c52ebbeec","examples/dump-wincon.rs":"bd0ffadd14eed711fc74d64caff5ce98bb5c5b3f0b313b54ac759b5a6c6a289b","examples/set-wincon.rs":"b8bc444537449bf334a1e26dd010986c16cb260567f87ae9597fc869c936fe6a","src/ansi.rs":"1b0166d064fe261bc012acca2f3ff442703a774e5fa4b8e96f63dce87b7e73d1","src/lib.rs":"4b4415a0684901bab712dbe94aec960792760aa1db5505adacfdc43db2cd93a7","src/stream.rs":"afdbd6e314127bd412e81894a857cb95fe3140e2b994e17e4e5580ef113a4159","src/windows.rs":"e4aeae1b32f6348b6b9c54e0cd54d9a3c08c6f250c7313fcaa59e3d8a8f51c97"},"package":"1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"}
{"files":{"Cargo.lock":"0c938cccccd7b700cab49cb55fe6625c91e73816df9f3d5690b8e162188d8611","Cargo.toml":"a10db4e9f6dcf87978b85f004a23f99c37a2845be660f4600ba5209a5218e903","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"73b0d84e4b954ce904a00043379767ae2a5f8d4f40564639cee230f639fe4dae","README.md":"513a578c6c2ea39a811e2038358e512cbc0c709e3a7c18303871ec2c52ebbeec","examples/dump-wincon.rs":"ab7de9e396556ebb8abb85a766fbe307f70071676d0b37680af7eed6a012434b","examples/set-wincon.rs":"faf9bf4be8fec055aa98f59c997c0e2b788aa9dcaa927211f926be7632e38a33","src/ansi.rs":"1b0166d064fe261bc012acca2f3ff442703a774e5fa4b8e96f63dce87b7e73d1","src/lib.rs":"e63d786f494e3d2ff78a2e96501966c848c7753c058ef5966e02506a8936b152","src/stream.rs":"006e4c437fe5a5d0efa6204c7026a703c6058b0842be3daab8801461857b861a","src/windows.rs":"e4aeae1b32f6348b6b9c54e0cd54d9a3c08c6f250c7313fcaa59e3d8a8f51c97"},"package":"5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"}

45
vendor/anstyle-wincon/Cargo.lock generated vendored
View File

@ -4,13 +4,13 @@ version = 3
[[package]]
name = "anstyle"
version = "1.0.0"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
checksum = "15c4c2c83f81532e5845a733998b6971faca23490340a418e9b72a3ec9de12ea"
[[package]]
name = "anstyle-wincon"
version = "3.0.2"
version = "3.0.4"
dependencies = [
"anstyle",
"lexopt",
@ -34,13 +34,14 @@ dependencies = [
[[package]]
name = "windows-targets"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
@ -49,42 +50,48 @@ dependencies = [
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]]
name = "windows_i686_gnu"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
[[package]]
name = "windows_i686_msvc"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.0"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"

View File

@ -11,9 +11,10 @@
[package]
edition = "2021"
rust-version = "1.70.0"
rust-version = "1.65.0"
name = "anstyle-wincon"
version = "3.0.2"
version = "3.0.4"
build = false
include = [
"build.rs",
"src/**/*",
@ -24,6 +25,10 @@ include = [
"benches/**/*",
"examples/**/*",
]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Styling legacy Windows terminals"
homepage = "https://github.com/rust-cli/anstyle"
readme = "README.md"
@ -38,7 +43,7 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-cli/anstyle.git"
[package.metadata.docs.rs]
features = []
all-features = true
rustdoc-args = [
"--cfg",
"docsrs",
@ -80,6 +85,18 @@ replace = """
[Unreleased]: https://github.com/rust-cli/anstyle/compare/{{tag_name}}...HEAD"""
search = "<!-- next-url -->"
[lib]
name = "anstyle_wincon"
path = "src/lib.rs"
[[example]]
name = "dump-wincon"
path = "examples/dump-wincon.rs"
[[example]]
name = "set-wincon"
path = "examples/set-wincon.rs"
[dependencies.anstyle]
version = "1.0.0"
@ -92,3 +109,73 @@ features = [
"Win32_System_Console",
"Win32_Foundation",
]
[lints.clippy]
bool_assert_comparison = "allow"
branches_sharing_code = "allow"
checked_conversions = "warn"
collapsible_else_if = "allow"
create_dir = "warn"
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
doc_markdown = "warn"
empty_enum = "warn"
enum_glob_use = "warn"
expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
fallible_impl_from = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
float_cmp_const = "warn"
fn_params_excessive_bools = "warn"
from_iter_instead_of_collect = "warn"
if_same_then_else = "allow"
implicit_clone = "warn"
imprecise_flops = "warn"
inconsistent_struct_constructor = "warn"
inefficient_to_string = "warn"
infinite_loop = "warn"
invalid_upcast_comparisons = "warn"
items_after_statements = "warn"
large_digit_groups = "warn"
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
let_and_return = "allow"
linkedlist = "warn"
lossy_float_literal = "warn"
macro_use_imports = "warn"
match_wildcard_for_single_variants = "warn"
mem_forget = "warn"
mutex_integer = "warn"
needless_continue = "warn"
needless_for_each = "warn"
negative_feature_names = "warn"
path_buf_push_overwrite = "warn"
ptr_as_ptr = "warn"
rc_mutex = "warn"
redundant_feature_names = "warn"
ref_option_ref = "warn"
rest_pat_in_fully_bound_structs = "warn"
same_functions_in_if_condition = "warn"
self_named_module_files = "warn"
semicolon_if_nothing_returned = "warn"
single_match_else = "warn"
str_to_string = "warn"
string_add = "warn"
string_add_assign = "warn"
string_lit_as_bytes = "warn"
string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
verbose_file_reads = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
[lints.rust]
rust_2018_idioms = "warn"
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
unused_qualifications = "warn"

View File

@ -1,3 +1,5 @@
//! Write colored text using wincon API calls
use anstyle_wincon::WinconStream as _;
fn main() -> Result<(), lexopt::Error> {
@ -13,32 +15,33 @@ fn main() -> Result<(), lexopt::Error> {
}
}
for r in 0..6 {
for fixed in 16..232 {
let col = (fixed - 16) % 36;
if col == 0 {
let _ = stdout.write_colored(None, None, &b"\n"[..]);
for g in 0..6 {
for b in 0..6 {
let fixed = r * 36 + g * 6 + b + 16;
}
let style = style(fixed, args.layer, args.effects);
let _ = print_number(&mut stdout, fixed, style);
}
let _ = stdout.write_colored(None, None, &b"\n"[..]);
}
}
for c in 0..24 {
if 0 == c % 8 {
let _ = stdout.write_colored(None, None, &b"\n"[..]);
}
let fixed = 232 + c;
let _ = stdout.write_colored(None, None, &b"\n"[..]);
for fixed in 232..=255 {
let style = style(fixed, args.layer, args.effects);
let _ = print_number(&mut stdout, fixed, style);
}
let _ = stdout.write_colored(None, None, &b"\n"[..]);
Ok(())
}
fn style(fixed: u8, layer: Layer, effects: anstyle::Effects) -> anstyle::Style {
let color = anstyle::Ansi256Color(fixed).into();
fn style(
color: impl Into<anstyle::Color>,
layer: Layer,
effects: anstyle::Effects,
) -> anstyle::Style {
let color = color.into();
(match layer {
Layer::Fg => anstyle::Style::new().fg_color(Some(color)),
Layer::Bg => anstyle::Style::new().bg_color(Some(color)),
@ -63,7 +66,7 @@ fn print_number(
});
stdout
.write_colored(fg, bg, format!("{:>4}", fixed).as_bytes())
.write_colored(fg, bg, format!("{:>3X}", fixed).as_bytes())
.map(|_| ())
}

View File

@ -1,3 +1,5 @@
//! Interactively manipulate wincon colors
#![cfg_attr(not(windows), allow(dead_code))]
#[cfg(not(windows))]

View File

@ -9,6 +9,9 @@
//! - More focused, smaller
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
#![warn(clippy::print_stderr)]
#![warn(clippy::print_stdout)]
pub mod ansi;
mod stream;

View File

@ -101,9 +101,7 @@ impl WinconStream for std::io::Stderr {
#[cfg(not(windows))]
mod platform {
use super::*;
impl WinconStream for std::io::StdoutLock<'_> {
impl super::WinconStream for std::io::StdoutLock<'_> {
fn write_colored(
&mut self,
fg: Option<anstyle::AnsiColor>,
@ -114,7 +112,7 @@ mod platform {
}
}
impl WinconStream for std::io::StderrLock<'_> {
impl super::WinconStream for std::io::StderrLock<'_> {
fn write_colored(
&mut self,
fg: Option<anstyle::AnsiColor>,
@ -128,9 +126,7 @@ mod platform {
#[cfg(windows)]
mod platform {
use super::*;
impl WinconStream for std::io::StdoutLock<'_> {
impl super::WinconStream for std::io::StdoutLock<'_> {
fn write_colored(
&mut self,
fg: Option<anstyle::AnsiColor>,
@ -142,7 +138,7 @@ mod platform {
}
}
impl WinconStream for std::io::StderrLock<'_> {
impl super::WinconStream for std::io::StderrLock<'_> {
fn write_colored(
&mut self,
fg: Option<anstyle::AnsiColor>,

View File

@ -1 +1 @@
{"files":{"Cargo.lock":"1bef7628bf2ce069e9daf318cd7798770fee9bb3e5b78a6cc46118aff8c54c3e","Cargo.toml":"11b43506ab8336272c179d16a2f06cbf30636458d1c09eaa93ee9a8ab0d31eda","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"3dad3b7606dec7ce40f54546e0dd485aeb52a45d4fcdfdaf830fd8349bbe43a5","README.md":"dcb157ba695dd8f1572944cc5bf84b8f67f8bb73925a5b725a9e274c755ce1a6","examples/dump-style.rs":"21aaf02b1d7d7cccec3af4135fc5c1ca187e3a34af52229bde6ab3d56724f471","src/color.rs":"1c02bf27d036167e8bff57e34d1b29ba4393175b37cf3f6305c685e4cd28469b","src/effect.rs":"36ac77258c644e25f678b0d773454ba0f59f011d5de23a1894ad9e21bae00ae3","src/lib.rs":"0106395ba7263dbee67458e5ff4038cab493a3d34f3dcf0cb75504b1531a58e1","src/macros.rs":"0c90b45626fe8331d5b3326abb831f4ba6e04bcc975b1b9c01e465715050caa2","src/reset.rs":"f125a91d412b102a32e23a0a4147b30eb4588a914194a792167f7348fa5841e5","src/style.rs":"bad204f209928d2afe5260f2df95be9df3903fe16ccbf04f1795765b3285b60a"},"package":"8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"}
{"files":{"Cargo.lock":"f1b654e343f2784fcee83c618945ba6ebfd0dfa378f2d77c231348150322c58b","Cargo.toml":"647d64af5a7a10bdad5bc17e6678315d80382da525737f04e05a8a9ff996ce31","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"3dad3b7606dec7ce40f54546e0dd485aeb52a45d4fcdfdaf830fd8349bbe43a5","README.md":"dcb157ba695dd8f1572944cc5bf84b8f67f8bb73925a5b725a9e274c755ce1a6","examples/dump-style.rs":"a6c89b70be79594485312ec4670886ea9f4bebbf2f39fedfbd16d92745824f82","src/color.rs":"5a53d01fe9c28794ffbbf6f687f2f2ab70f19beea583bbdf7bdf874ea8280886","src/effect.rs":"f4dc053212f0a0da33fb75ad5888feaf8a76be382e889e002f9e9c74885f98a2","src/lib.rs":"fdd7cb0f5ae4b6a964be6bccd0651dbde50d7bf82a24c044f4cc4ac61957e8dd","src/macros.rs":"0c90b45626fe8331d5b3326abb831f4ba6e04bcc975b1b9c01e465715050caa2","src/reset.rs":"df498292ee2670f40e101a99099135db29c603a01b7cb5124e4cd5e553b4e84b","src/style.rs":"9dbe81c3efc24603ba1bac2a8297f5118398b5799e546b1236e84767e181d3f0"},"package":"1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"}

2
vendor/anstyle/Cargo.lock generated vendored
View File

@ -4,7 +4,7 @@ version = 3
[[package]]
name = "anstyle"
version = "1.0.6"
version = "1.0.8"
dependencies = [
"lexopt",
]

View File

@ -11,9 +11,10 @@
[package]
edition = "2021"
rust-version = "1.70.0"
rust-version = "1.65.0"
name = "anstyle"
version = "1.0.6"
version = "1.0.8"
build = false
include = [
"build.rs",
"src/**/*",
@ -24,6 +25,10 @@ include = [
"benches/**/*",
"examples/**/*",
]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "ANSI text styling"
homepage = "https://github.com/rust-cli/anstyle"
readme = "README.md"
@ -37,6 +42,13 @@ categories = ["command-line-interface"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-cli/anstyle.git"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = [
"--cfg",
"docsrs",
]
[package.metadata.release]
tag-prefix = ""
@ -75,6 +87,14 @@ replace = """
[Unreleased]: https://github.com/rust-cli/anstyle/compare/{{tag_name}}...HEAD"""
search = "<!-- next-url -->"
[lib]
name = "anstyle"
path = "src/lib.rs"
[[example]]
name = "dump-style"
path = "examples/dump-style.rs"
[dependencies]
[dev-dependencies.lexopt]
@ -83,3 +103,73 @@ version = "0.3.0"
[features]
default = ["std"]
std = []
[lints.clippy]
bool_assert_comparison = "allow"
branches_sharing_code = "allow"
checked_conversions = "warn"
collapsible_else_if = "allow"
create_dir = "warn"
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
doc_markdown = "warn"
empty_enum = "warn"
enum_glob_use = "warn"
expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
fallible_impl_from = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
float_cmp_const = "warn"
fn_params_excessive_bools = "warn"
from_iter_instead_of_collect = "warn"
if_same_then_else = "allow"
implicit_clone = "warn"
imprecise_flops = "warn"
inconsistent_struct_constructor = "warn"
inefficient_to_string = "warn"
infinite_loop = "warn"
invalid_upcast_comparisons = "warn"
items_after_statements = "warn"
large_digit_groups = "warn"
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
let_and_return = "allow"
linkedlist = "warn"
lossy_float_literal = "warn"
macro_use_imports = "warn"
match_wildcard_for_single_variants = "warn"
mem_forget = "warn"
mutex_integer = "warn"
needless_continue = "warn"
needless_for_each = "warn"
negative_feature_names = "warn"
path_buf_push_overwrite = "warn"
ptr_as_ptr = "warn"
rc_mutex = "warn"
redundant_feature_names = "warn"
ref_option_ref = "warn"
rest_pat_in_fully_bound_structs = "warn"
same_functions_in_if_condition = "warn"
self_named_module_files = "warn"
semicolon_if_nothing_returned = "warn"
single_match_else = "warn"
str_to_string = "warn"
string_add = "warn"
string_add_assign = "warn"
string_lit_as_bytes = "warn"
string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
verbose_file_reads = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
[lints.rust]
rust_2018_idioms = "warn"
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
unused_qualifications = "warn"

View File

@ -1,3 +1,5 @@
//! Write ANSI escape code colored text
use std::io::Write;
fn main() -> Result<(), lexopt::Error> {
@ -6,31 +8,31 @@ fn main() -> Result<(), lexopt::Error> {
let mut stdout = stdout.lock();
for fixed in 0..16 {
let style = style(fixed, args.layer, args.effects);
let color = anstyle::Ansi256Color(fixed)
.into_ansi()
.expect("4-bit range used");
let style = style(color, args.layer, args.effects);
let _ = print_number(&mut stdout, fixed, style);
if fixed == 7 || fixed == 15 {
let _ = writeln!(&mut stdout);
}
}
for r in 0..6 {
for fixed in 16..232 {
let col = (fixed - 16) % 36;
if col == 0 {
let _ = writeln!(stdout);
for g in 0..6 {
for b in 0..6 {
let fixed = r * 36 + g * 6 + b + 16;
let style = style(fixed, args.layer, args.effects);
}
let color = anstyle::Ansi256Color(fixed);
let style = style(color, args.layer, args.effects);
let _ = print_number(&mut stdout, fixed, style);
}
let _ = writeln!(stdout);
}
}
for c in 0..24 {
if 0 == c % 8 {
let _ = writeln!(stdout);
}
let fixed = 232 + c;
let style = style(fixed, args.layer, args.effects);
let _ = writeln!(stdout);
for fixed in 232..=255 {
let color = anstyle::Ansi256Color(fixed);
let style = style(color, args.layer, args.effects);
let _ = print_number(&mut stdout, fixed, style);
}
@ -39,8 +41,12 @@ fn main() -> Result<(), lexopt::Error> {
Ok(())
}
fn style(fixed: u8, layer: Layer, effects: anstyle::Effects) -> anstyle::Style {
let color = anstyle::Ansi256Color(fixed).into();
fn style(
color: impl Into<anstyle::Color>,
layer: Layer,
effects: anstyle::Effects,
) -> anstyle::Style {
let color = color.into();
(match layer {
Layer::Fg => anstyle::Style::new().fg_color(Some(color)),
Layer::Bg => anstyle::Style::new().bg_color(Some(color)),
@ -53,13 +59,7 @@ fn print_number(
fixed: u8,
style: anstyle::Style,
) -> std::io::Result<()> {
write!(
stdout,
"{}{:>4}{}",
style.render(),
fixed,
anstyle::Reset.render()
)
write!(stdout, "{style}{fixed:>3X}{style:#}",)
}
#[derive(Default)]

View File

@ -1,8 +1,18 @@
/// Any ANSI color code scheme
#[allow(clippy::exhaustive_enums)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Color {
/// Available 4-bit ANSI color palette codes
///
/// The user's terminal defines the meaning of the each palette code.
Ansi(AnsiColor),
/// 256 (8-bit) color support
///
/// - `0..16` are [`AnsiColor`] palette codes
/// - `0..232` map to [`RgbColor`] color values
/// - `232..` map to [`RgbColor`] gray-scale values
Ansi256(Ansi256Color),
/// 24-bit ANSI RGB color codes
Rgb(RgbColor),
}
@ -23,7 +33,7 @@ impl Color {
/// Render the ANSI code for a foreground color
#[inline]
pub fn render_fg(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render_fg(self) -> impl core::fmt::Display + Copy {
match self {
Self::Ansi(color) => color.as_fg_buffer(),
Self::Ansi256(color) => color.as_fg_buffer(),
@ -44,7 +54,7 @@ impl Color {
/// Render the ANSI code for a background color
#[inline]
pub fn render_bg(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render_bg(self) -> impl core::fmt::Display + Copy {
match self {
Self::Ansi(color) => color.as_bg_buffer(),
Self::Ansi256(color) => color.as_bg_buffer(),
@ -64,7 +74,7 @@ impl Color {
}
#[inline]
pub(crate) fn render_underline(self) -> impl core::fmt::Display + Copy + Clone {
pub(crate) fn render_underline(self) -> impl core::fmt::Display + Copy {
match self {
Self::Ansi(color) => color.as_underline_buffer(),
Self::Ansi256(color) => color.as_underline_buffer(),
@ -122,6 +132,7 @@ impl From<(u8, u8, u8)> for Color {
/// Available 4-bit ANSI color palette codes
///
/// The user's terminal defines the meaning of the each palette code.
#[allow(clippy::exhaustive_enums)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum AnsiColor {
@ -191,7 +202,7 @@ impl AnsiColor {
/// Render the ANSI code for a foreground color
#[inline]
pub fn render_fg(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render_fg(self) -> impl core::fmt::Display + Copy {
NullFormatter(self.as_fg_str())
}
@ -224,7 +235,7 @@ impl AnsiColor {
/// Render the ANSI code for a background color
#[inline]
pub fn render_bg(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render_bg(self) -> impl core::fmt::Display + Copy {
NullFormatter(self.as_bg_str())
}
@ -335,6 +346,7 @@ impl AnsiColor {
/// - `0..16` are [`AnsiColor`] palette codes
/// - `0..232` map to [`RgbColor`] color values
/// - `232..` map to [`RgbColor`] gray-scale values
#[allow(clippy::exhaustive_structs)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct Ansi256Color(pub u8);
@ -354,11 +366,13 @@ impl Ansi256Color {
crate::Style::new().fg_color(Some(Color::Ansi256(self)))
}
/// Get the raw value
#[inline]
pub const fn index(self) -> u8 {
self.0
}
/// Convert to [`AnsiColor`] when there is a 1:1 mapping
#[inline]
pub const fn into_ansi(self) -> Option<AnsiColor> {
match self.index() {
@ -382,6 +396,7 @@ impl Ansi256Color {
}
}
/// Losslessly convert from [`AnsiColor`]
#[inline]
pub const fn from_ansi(color: AnsiColor) -> Self {
match color {
@ -406,7 +421,7 @@ impl Ansi256Color {
/// Render the ANSI code for a foreground color
#[inline]
pub fn render_fg(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render_fg(self) -> impl core::fmt::Display + Copy {
self.as_fg_buffer()
}
@ -420,7 +435,7 @@ impl Ansi256Color {
/// Render the ANSI code for a background color
#[inline]
pub fn render_bg(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render_bg(self) -> impl core::fmt::Display + Copy {
self.as_bg_buffer()
}
@ -456,6 +471,7 @@ impl From<AnsiColor> for Ansi256Color {
}
/// 24-bit ANSI RGB color codes
#[allow(clippy::exhaustive_structs)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RgbColor(pub u8, pub u8, pub u8);
@ -474,16 +490,19 @@ impl RgbColor {
crate::Style::new().fg_color(Some(Color::Rgb(self)))
}
/// Red
#[inline]
pub const fn r(self) -> u8 {
self.0
}
/// Green
#[inline]
pub const fn g(self) -> u8 {
self.1
}
/// Blue
#[inline]
pub const fn b(self) -> u8 {
self.2
@ -491,7 +510,7 @@ impl RgbColor {
/// Render the ANSI code for a foreground color
#[inline]
pub fn render_fg(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render_fg(self) -> impl core::fmt::Display + Copy {
self.as_fg_buffer()
}
@ -509,7 +528,7 @@ impl RgbColor {
/// Render the ANSI code for a background color
#[inline]
pub fn render_bg(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render_bg(self) -> impl core::fmt::Display + Copy {
self.as_bg_buffer()
}
@ -592,7 +611,10 @@ impl DisplayBuffer {
#[inline]
fn as_str(&self) -> &str {
// SAFETY: Only `&str` can be written to the buffer
unsafe { core::str::from_utf8_unchecked(&self.buffer[0..self.len]) }
#[allow(unsafe_code)]
unsafe {
core::str::from_utf8_unchecked(&self.buffer[0..self.len])
}
}
#[inline]

View File

@ -9,21 +9,30 @@
pub struct Effects(u16);
impl Effects {
/// No [`Effects`] applied
const PLAIN: Self = Effects(0);
#[allow(missing_docs)]
pub const BOLD: Self = Effects(1 << 0);
#[allow(missing_docs)]
pub const DIMMED: Self = Effects(1 << 1);
/// Not widely supported. Sometimes treated as inverse or blink
pub const ITALIC: Self = Effects(1 << 2);
/// Style extensions exist for Kitty, VTE, mintty and iTerm2.
pub const UNDERLINE: Self = Effects(1 << 3);
#[allow(missing_docs)]
pub const DOUBLE_UNDERLINE: Self = Effects(1 << 4);
#[allow(missing_docs)]
pub const CURLY_UNDERLINE: Self = Effects(1 << 5);
#[allow(missing_docs)]
pub const DOTTED_UNDERLINE: Self = Effects(1 << 6);
#[allow(missing_docs)]
pub const DASHED_UNDERLINE: Self = Effects(1 << 7);
#[allow(missing_docs)]
pub const BLINK: Self = Effects(1 << 8);
/// Swap foreground and background colors; inconsistent emulation
pub const INVERT: Self = Effects(1 << 9);
#[allow(missing_docs)]
pub const HIDDEN: Self = Effects(1 << 10);
/// Characters legible but marked as if for deletion. Not supported in Terminal.app
pub const STRIKETHROUGH: Self = Effects(1 << 11);
@ -156,7 +165,7 @@ impl Effects {
/// Render the ANSI code
#[inline]
pub fn render(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render(self) -> impl core::fmt::Display + Copy {
EffectsDisplay(self)
}
@ -321,6 +330,7 @@ impl core::fmt::Display for EffectsDisplay {
}
}
/// Enumerate each enabled value in [`Effects`]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct EffectIter {
index: usize,

View File

@ -25,11 +25,12 @@
//!
//! User-styling parsers:
//! - [anstyle-git](https://docs.rs/anstyle-git): Parse Git style descriptions
//! - [anstyle-ls](https://docs.rs/anstyle-ls): Parse LS_COLORS style descriptions
//! - [anstyle-ls](https://docs.rs/anstyle-ls): Parse `LS_COLORS` style descriptions
//!
//! Convert to other formats
//! - [anstream](https://docs.rs/anstream): A simple cross platform library for writing colored text to a terminal
//! - [anstyle-roff](https://docs.rs/anstyle-roff): For converting to ROFF
//! - [anstyle-syntect](https://docs.rs/anstyle-syntect): For working with syntax highlighting
//!
//! Utilities
//! - [anstyle-lossy](https://docs.rs/anstyle-lossy): Convert between `anstyle::Color` types
@ -44,6 +45,10 @@
//! ```
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
#![warn(clippy::print_stderr)]
#![warn(clippy::print_stdout)]
#[macro_use]
mod macros;

View File

@ -1,4 +1,5 @@
/// Reset terminal formatting
#[allow(clippy::exhaustive_structs)]
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Reset;
@ -7,7 +8,7 @@ impl Reset {
///
/// `Reset` also implements `Display` directly, so calling this method is optional.
#[inline]
pub fn render(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render(self) -> impl core::fmt::Display + Copy {
self
}
}

View File

@ -101,7 +101,7 @@ impl Style {
///
/// `Style` also implements `Display` directly, so calling this method is optional.
#[inline]
pub fn render(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render(self) -> impl core::fmt::Display + Copy {
StyleDisplay(self)
}
@ -150,7 +150,7 @@ impl Style {
///
/// Unlike [`Reset::render`][crate::Reset::render], this will elide the code if there is nothing to reset.
#[inline]
pub fn render_reset(self) -> impl core::fmt::Display + Copy + Clone {
pub fn render_reset(self) -> impl core::fmt::Display + Copy {
if self != Self::new() {
RESET
} else {
@ -289,27 +289,32 @@ impl Style {
/// # Reflection
impl Style {
/// Get the foreground color
#[inline]
pub const fn get_fg_color(self) -> Option<crate::Color> {
self.fg
}
/// Get the background color
#[inline]
#[allow(missing_docs)]
pub const fn get_bg_color(self) -> Option<crate::Color> {
self.bg
}
#[inline]
#[allow(missing_docs)]
pub const fn get_underline_color(self) -> Option<crate::Color> {
self.underline
}
#[inline]
#[allow(missing_docs)]
pub const fn get_effects(self) -> crate::Effects {
self.effects
}
/// Check if no effects are enabled
/// Check if no styling is enabled
#[inline]
pub const fn is_plain(self) -> bool {
self.fg.is_none()
@ -395,7 +400,7 @@ impl core::ops::SubAssign<crate::Effects> for Style {
/// assert_ne!(anstyle::Effects::UNDERLINE | effects, effects);
/// assert_ne!(anstyle::RgbColor(0, 0, 0).on_default() | effects, effects);
/// ```
impl core::cmp::PartialEq<crate::Effects> for Style {
impl PartialEq<crate::Effects> for Style {
#[inline]
fn eq(&self, other: &crate::Effects) -> bool {
let other = Self::from(*other);
@ -424,6 +429,7 @@ impl core::fmt::Display for StyleDisplay {
}
#[test]
#[cfg(feature = "std")]
fn print_size_of() {
use std::mem::size_of;
dbg!(size_of::<Style>());

View File

@ -1 +1 @@
{"files":{"Cargo.lock":"ff016e656e3e2fe749385004fe8fee304a9a4a82fbeaf7a47a9784cdee636129","Cargo.toml":"3db870621795ec0318455348aa94d649a08ee46737d3b8d2b05dc3d6c2b915ba","LICENSE":"1bc7e6f475b3ec99b7e2643411950ae2368c250dd4c5c325f80f9811362a94a1","README.md":"f77d8910fa16f9f0ad2d72d039a7e8ac2979834e0acf435b7c84744c90cb21ec","examples/array_refs.rs":"336b52f6ab31d78766bd1653cea60b9f183d80369f3feec55e454ccbcb3adaaa","examples/array_refs_with_const.rs":"9e49959de714c611bc2e48bb0dd51c3023abc2b3e6b6e0428e7d7b30be8900e4","examples/simple-case.rs":"12a7c596db0d8e89415dfd75a8fe390a7141b24771ad70aee73286857a37b5fb","src/lib.rs":"6ade4aa7e3ffb5960e0bc43fd6f2594a0ccd0332ee17f8278950140803470429"},"package":"6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"}
{"files":{"Cargo.lock":"a662fab7d33586364087c438737169ac88fbdc810973374a2196f6b0d45484b5","Cargo.toml":"517b570f4136de5b5a07e1c41a84d6876227b09aab84e69e578bfa8be2e67546","LICENSE":"1bc7e6f475b3ec99b7e2643411950ae2368c250dd4c5c325f80f9811362a94a1","README.md":"039b4028d39ba4ec049041dbbf949555bcc42aa7bced920725c5573d2b6cad24","examples/array_refs.rs":"f0cda2c12723da36d722fc820c027c64f4f48fe0a62e6dec7bb4f62cf5197148","examples/array_refs_with_const.rs":"d04c8f8db0989ed0c3adee472923d673d25155fad8297f9860dde9a79d8df679","examples/simple-case.rs":"bfd9bd711e18fe23d0016e9856467d00717dd611522e01d227f7ba525e635280","src/lib.rs":"b74872c9bb2b836132817e024a3f9205f83a6864de1a9bfb46acc1bfbbc1873a"},"package":"76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"}

163
vendor/arrayref/Cargo.lock generated vendored
View File

@ -4,31 +4,20 @@ version = 3
[[package]]
name = "aho-corasick"
version = "0.7.20"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "arrayref"
version = "0.3.7"
version = "0.3.9"
dependencies = [
"quickcheck",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -37,73 +26,48 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "env_logger"
version = "0.5.13"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38"
checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
]
[[package]]
name = "humantime"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
dependencies = [
"quick-error",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.140"
version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "log"
version = "0.4.17"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "memchr"
version = "2.5.0"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "quickcheck"
version = "0.6.2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c01babc5ffd48a2a83744b3024814bb46dfd4f2a4705ccb44b1b60e644fdcab7"
checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6"
dependencies = [
"env_logger",
"log",
@ -112,46 +76,39 @@ dependencies = [
[[package]]
name = "rand"
version = "0.4.6"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"fuchsia-cprng",
"libc",
"rand_core 0.3.1",
"rdrand",
"winapi",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.3.1"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
"rand_core 0.3.1",
"getrandom",
]
[[package]]
name = "regex"
version = "1.7.1"
version = "1.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
dependencies = [
"aho-corasick",
"memchr",
@ -160,46 +117,12 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.28"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]]
name = "termcolor"
version = "1.2.0"
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
dependencies = [
"winapi-util",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"

View File

@ -11,7 +11,7 @@
[package]
name = "arrayref"
version = "0.3.7"
version = "0.3.9"
authors = ["David Roundy <roundyd@physics.oregonstate.edu>"]
description = "Macros to take array references of slices"
documentation = "https://docs.rs/arrayref"
@ -20,4 +20,4 @@ license = "BSD-2-Clause"
repository = "https://github.com/droundy/arrayref"
[dev-dependencies.quickcheck]
version = "0.6"
version = "1.0"

View File

@ -106,4 +106,4 @@ explicit. Moreover (although I have not tested this), the use of
array references rather than slices *should* result in far fewer
bounds checks, since almost all sizes are known at compile time.
[2]: https://github.com/droundy/onionsalt/blob/master/src/crypto.rs
[2]: https://github.com/droundy/onionsalt/blob/master/src/crypto/mod.rs

View File

@ -58,7 +58,7 @@ macro_rules! array_ref {
($arr:expr, $offset:expr, $len:expr) => {{
{
#[inline]
unsafe fn as_array<T>(slice: &[T]) -> &[T; $len] {
const unsafe fn as_array<T>(slice: &[T]) -> &[T; $len] {
&*(slice.as_ptr() as *const [_; $len])
}
let offset = $offset;
@ -68,7 +68,7 @@ macro_rules! array_ref {
as_array(slice)
}
}
}}
}};
}
/// You can use `array_refs` to generate a series of array references
@ -109,10 +109,11 @@ macro_rules! array_refs {
#[inline]
#[allow(unused_assignments)]
#[allow(clippy::eval_order_dependence)]
unsafe fn as_arrays<T>(a: &[T]) -> ( $( &[T; $pre], )* &[T], $( &[T; $post], )*) {
let min_len = $( $pre + )* $( $post + )* 0;
let var_len = a.len() - min_len;
assert!(a.len() >= min_len);
const unsafe fn as_arrays<T>(a: &[T]) -> ( $( &[T; $pre], )* &[T], $( &[T; $post], )*) {
const MIN_LEN: usize = 0usize $( .saturating_add($pre) )* $( .saturating_add($post) )*;
assert!(MIN_LEN < usize::MAX, "Your arrays are too big, are you trying to hack yourself?!");
let var_len = a.len() - MIN_LEN;
assert!(a.len() >= MIN_LEN);
let mut p = a.as_ptr();
( $( {
let aref = & *(p as *const [T; $pre]);
@ -140,7 +141,7 @@ macro_rules! array_refs {
#[inline]
#[allow(unused_assignments)]
#[allow(clippy::eval_order_dependence)]
unsafe fn as_arrays<T>(a: &[T; $( $len + )* 0 ]) -> ( $( &[T; $len], )* ) {
const unsafe fn as_arrays<T>(a: &[T; $( $len + )* 0 ]) -> ( $( &[T; $len], )* ) {
let mut p = a.as_ptr();
( $( {
let aref = &*(p as *const [T; $len]);
@ -157,7 +158,6 @@ macro_rules! array_refs {
}}
}
/// You can use `mut_array_refs` to generate a series of mutable array
/// references to an input mutable array reference. The idea is if
/// you want to break an array into a series of contiguous and
@ -207,9 +207,10 @@ macro_rules! mut_array_refs {
#[allow(unused_assignments)]
#[allow(clippy::eval_order_dependence)]
unsafe fn as_arrays<T>(a: &mut [T]) -> ( $( &mut [T; $pre], )* &mut [T], $( &mut [T; $post], )*) {
let min_len = $( $pre + )* $( $post + )* 0;
let var_len = a.len() - min_len;
assert!(a.len() >= min_len);
const MIN_LEN: usize = 0usize $( .saturating_add($pre) )* $( .saturating_add($post) )*;
assert!(MIN_LEN < usize::MAX, "Your arrays are too big, are you trying to hack yourself?!");
let var_len = a.len() - MIN_LEN;
assert!(a.len() >= MIN_LEN);
let mut p = a.as_mut_ptr();
( $( {
let aref = &mut *(p as *mut [T; $pre]);
@ -293,10 +294,9 @@ macro_rules! array_mut_ref {
as_array(slice)
}
}
}}
}};
}
#[allow(clippy::all)]
#[cfg(test)]
mod test {
@ -336,11 +336,12 @@ fn simple_case_works() {
check([0, 0, 10], array_ref!(foo, 8, 3));
}
#[test]
fn check_array_ref_5() {
fn f(data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
if data.len() < offset + 5 {
// Compute the following, with correct results even if the sum would overflow:
// if data.len() < offset + 5
if data.len() < 5 || data.len() - 5 < offset {
return quickcheck::TestResult::discard();
}
let out = array_ref!(data, offset, 5);
@ -352,7 +353,9 @@ fn check_array_ref_5() {
#[test]
fn check_array_ref_out_of_bounds_5() {
fn f(data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
if data.len() >= offset + 5 {
// Compute the following, with correct results even if the sum would overflow:
// if data.len() >= offset + 5
if data.len() >= 5 && data.len() - 5 >= offset {
return quickcheck::TestResult::discard();
}
quickcheck::TestResult::must_fail(move || {
@ -365,7 +368,9 @@ fn check_array_ref_out_of_bounds_5() {
#[test]
fn check_array_mut_ref_7() {
fn f(mut data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
if data.len() < offset + 7 {
// Compute the following, with correct results even if the sum would overflow:
// if data.len() < offset + 7
if data.len() < 7 || data.len() - 7 < offset {
return quickcheck::TestResult::discard();
}
let out = array_mut_ref!(data, offset, 7);
@ -375,11 +380,12 @@ fn check_array_mut_ref_7() {
quickcheck::quickcheck(f as fn(Vec<u8>, usize) -> quickcheck::TestResult);
}
#[test]
fn check_array_mut_ref_out_of_bounds_32() {
fn f(mut data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
if data.len() >= offset + 32 {
// Compute the following, with correct results even if the sum would overflow:
// if data.len() >= offset + 32
if data.len() >= 32 && data.len() - 32 >= offset {
return quickcheck::TestResult::discard();
}
quickcheck::TestResult::must_fail(move || {
@ -389,7 +395,6 @@ fn check_array_mut_ref_out_of_bounds_32() {
quickcheck::quickcheck(f as fn(Vec<u8>, usize) -> quickcheck::TestResult);
}
#[test]
fn test_5_array_refs() {
let mut data: [usize; 128] = [0; 128];
@ -428,7 +433,6 @@ fn test_5_array_refs_dotdot() {
assert_eq!(e, array_ref![data, 118, 10]);
}
#[test]
fn test_5_mut_xarray_refs() {
let mut data: [usize; 128] = [0; 128];
@ -497,6 +501,4 @@ fn single_arg_refs() {
let (_,) = array_refs![&data,; ..;];
let (_,) = mut_array_refs![&mut data,; ..;];
}
} // mod test

View File

@ -1 +1 @@
{"files":{"CHANGELOG.md":"fc3afac61cfb6ed0370d35d8b7a01a9a4c43f07080ca6d7f4ed0ec5ffa1938a5","Cargo.toml":"bc1eb1e01f42009ada105cdcf8210471c9f988274a8e3874a362d169e90673dd","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"4da95ec4ecb65b738d470b7d762894ad9c97da93e6cbfb18b570fc2c96f4b871","README.md":"2264c34c62ea4c617d72047b00749b4786dfb9dff2fac24e0320170ee0cd19c8","benches/arraystring.rs":"fad1cecef71c290375befc77c75a868988b8d74135e8f8732bc5b58c85a8ab46","benches/extend.rs":"c38ecedbc88217a7e9fe1a73f916b168a96e48010a7ccd3dba5c3f8dea030d5d","src/array_string.rs":"39d9c33cdd3ec76e3dfd81996872c58d720877ef93fa7e8b23985d266230a2d6","src/arrayvec.rs":"50e2097cdfa4f1477c925daaf53cc7d59b31c66d11c0766cc1cbf14dad9dbc98","src/arrayvec_impl.rs":"e2642ae566c83ef37ad9aec6af7e3c50af310ba304553f38b2a787666b507580","src/char.rs":"1de50e1d6045af2b3496426492315ba774986f9bc8301ffa391de861a08cc9cb","src/errors.rs":"7fa2ff2350f811d52a210a7346c526d6715cacefd38a46e2d3b57ab7dc62b1ab","src/lib.rs":"8919a7e0c20890b1f094996147a1486d20578579aef03692315cd509e1745222","src/utils.rs":"d1cdc508dfca385e63f1f57bc8b53ed4a7f515e4ac1ebaa97b1d543fc8369432","tests/serde.rs":"117eb2961b5954d13c577edf60bbb07cb7481685cc9d6c49760a981d71465849","tests/tests.rs":"f8a18ff5deadb167832964ca0fff4f280129dd4a1de024e9cc76ffb7efe1c12c"},"package":"96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"}
{"files":{"CHANGELOG.md":"b6cd865fb2685cf241e61f216686c87fd78e7d4b8ba4faf03857c8a2b920eee6","Cargo.toml":"ed90cef00235d8e2b9a3027e11baed38b66a2cf6003bccd805c056c1ec70c722","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"4da95ec4ecb65b738d470b7d762894ad9c97da93e6cbfb18b570fc2c96f4b871","README.md":"2264c34c62ea4c617d72047b00749b4786dfb9dff2fac24e0320170ee0cd19c8","benches/arraystring.rs":"fad1cecef71c290375befc77c75a868988b8d74135e8f8732bc5b58c85a8ab46","benches/extend.rs":"c38ecedbc88217a7e9fe1a73f916b168a96e48010a7ccd3dba5c3f8dea030d5d","src/array_string.rs":"9840c5b95af997584374467dfc365e4ab747175db8e0574be4f148454514fc8f","src/arrayvec.rs":"42923c20659346e48fd551529cb58b8e646c404637818ba466455665cb037dc4","src/arrayvec_impl.rs":"e2642ae566c83ef37ad9aec6af7e3c50af310ba304553f38b2a787666b507580","src/char.rs":"1de50e1d6045af2b3496426492315ba774986f9bc8301ffa391de861a08cc9cb","src/errors.rs":"7fa2ff2350f811d52a210a7346c526d6715cacefd38a46e2d3b57ab7dc62b1ab","src/lib.rs":"8919a7e0c20890b1f094996147a1486d20578579aef03692315cd509e1745222","src/utils.rs":"d1cdc508dfca385e63f1f57bc8b53ed4a7f515e4ac1ebaa97b1d543fc8369432","tests/borsh.rs":"4ea4d21cc311d68d8f234cd77699a88158af26cbc3a69ae1f25c0052663f861d","tests/serde.rs":"117eb2961b5954d13c577edf60bbb07cb7481685cc9d6c49760a981d71465849","tests/tests.rs":"19a9bce4b55506be9ffb7584f47dbfb1d59c66dbfaab55b7a28d827cc0411e78"},"package":"7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"}

View File

@ -1,6 +1,21 @@
Recent Changes (arrayvec)
=========================
## 0.7.6
- Fix no-std build [#274](https://github.com/bluss/arrayvec/pull/274)
## 0.7.5
- Add `as_ptr` and `as_mut_ptr` to `ArrayString` [@YuhanLiin](https://github.com/YuhanLiin) [#260](https://github.com/bluss/arrayvec/pull/260)
- Add borsh serialization support by @honzasp and @Fuuzetsu [#259](https://github.com/bluss/arrayvec/pull/259)
- Move length field before before data in ArrayVec and ArrayString by @JakkuSakura [#255](https://github.com/bluss/arrayvec/pull/255)
- Fix miri error for ZST case in extend by @bluss
- implement AsRef<Path> for ArrayString by [@Zoybean](https://github.com/Zoybean) [#218](https://github.com/bluss/arrayvec/pull/218)
- Fix typos in changelog by [@striezel](https://github.com/striezel) [#241](https://github.com/bluss/arrayvec/pull/241)
- Add `as_slice`, `as_mut_slice` methods to `IntoIter` by [@clarfonthey](https://github.com/clarfonthey) [#224](https://github.com/bluss/arrayvec/pull/224)
## 0.7.4
- Add feature zeroize to support the `Zeroize` trait by @elichai
@ -118,7 +133,7 @@ Recent Changes (arrayvec)
users outside the crate.
- Add `FromStr` impl for `ArrayString` by @despawnerer
- Add method `try_extend_from_slice` to `ArrayVec`, which is always
effecient by @Thomasdezeeuw.
efficient by @Thomasdezeeuw.
- Add method `remaining_capacity` by @Thomasdezeeuw
- Improve performance of the `extend` method.
- The index type of zero capacity vectors is now itself zero size, by
@ -169,7 +184,7 @@ Recent Changes (arrayvec)
- Fix future compat warning about raw pointer casts
- Use `drop_in_place` when dropping the arrayvec by-value iterator
- Decrease mininum Rust version (see docs) by @jeehoonkang
- Decrease minimum Rust version (see docs) by @jeehoonkang
- 0.3.25

View File

@ -11,9 +11,15 @@
[package]
edition = "2018"
rust-version = "1.51"
name = "arrayvec"
version = "0.7.4"
version = "0.7.6"
authors = ["bluss"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "A vector with fixed capacity, backed by an array (it can be stored on the stack too). Implements fixed capacity ArrayVec and ArrayString."
documentation = "https://docs.rs/arrayvec/"
readme = "README.md"
@ -33,6 +39,7 @@ repository = "https://github.com/bluss/arrayvec"
[package.metadata.docs.rs]
features = [
"borsh",
"serde",
"zeroize",
]
@ -47,14 +54,37 @@ debug = 2
[profile.release]
debug = 2
[[bench]]
name = "extend"
harness = false
[lib]
name = "arrayvec"
path = "src/lib.rs"
[[test]]
name = "borsh"
path = "tests/borsh.rs"
[[test]]
name = "serde"
path = "tests/serde.rs"
[[test]]
name = "tests"
path = "tests/tests.rs"
[[bench]]
name = "arraystring"
path = "benches/arraystring.rs"
harness = false
[[bench]]
name = "extend"
path = "benches/extend.rs"
harness = false
[dependencies.borsh]
version = "1.2.0"
optional = true
default-features = false
[dependencies.serde]
version = "1.0"
optional = true

View File

@ -5,6 +5,8 @@ use std::fmt;
use std::hash::{Hash, Hasher};
use std::mem::MaybeUninit;
use std::ops::{Deref, DerefMut};
#[cfg(feature="std")]
use std::path::Path;
use std::ptr;
use std::slice;
use std::str;
@ -31,10 +33,11 @@ use serde::{Serialize, Deserialize, Serializer, Deserializer};
/// The string is a contiguous value that you can store directly on the stack
/// if needed.
#[derive(Copy)]
#[repr(C)]
pub struct ArrayString<const CAP: usize> {
// the `len` first elements of the array are initialized
xs: [MaybeUninit<u8>; CAP],
len: LenUint,
xs: [MaybeUninit<u8>; CAP],
}
impl<const CAP: usize> Default for ArrayString<CAP>
@ -414,11 +417,13 @@ impl<const CAP: usize> ArrayString<CAP>
self
}
fn as_ptr(&self) -> *const u8 {
/// Return a raw pointer to the string's buffer.
pub fn as_ptr(&self) -> *const u8 {
self.xs.as_ptr() as *const u8
}
fn as_mut_ptr(&mut self) -> *mut u8 {
/// Return a raw mutable pointer to the string's buffer.
pub fn as_mut_ptr(&mut self) -> *mut u8 {
self.xs.as_mut_ptr() as *mut u8
}
}
@ -498,6 +503,13 @@ impl<const CAP: usize> fmt::Debug for ArrayString<CAP>
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) }
}
#[cfg(feature="std")]
impl<const CAP: usize> AsRef<Path> for ArrayString<CAP> {
fn as_ref(&self) -> &Path {
self.as_str().as_ref()
}
}
impl<const CAP: usize> fmt::Display for ArrayString<CAP>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) }
@ -625,6 +637,37 @@ impl<'de, const CAP: usize> Deserialize<'de> for ArrayString<CAP>
}
}
#[cfg(feature = "borsh")]
/// Requires crate feature `"borsh"`
impl<const CAP: usize> borsh::BorshSerialize for ArrayString<CAP> {
fn serialize<W: borsh::io::Write>(&self, writer: &mut W) -> borsh::io::Result<()> {
<str as borsh::BorshSerialize>::serialize(&*self, writer)
}
}
#[cfg(feature = "borsh")]
/// Requires crate feature `"borsh"`
impl<const CAP: usize> borsh::BorshDeserialize for ArrayString<CAP> {
fn deserialize_reader<R: borsh::io::Read>(reader: &mut R) -> borsh::io::Result<Self> {
let len = <u32 as borsh::BorshDeserialize>::deserialize_reader(reader)? as usize;
if len > CAP {
return Err(borsh::io::Error::new(
borsh::io::ErrorKind::InvalidData,
format!("Expected a string no more than {} bytes long", CAP),
))
}
let mut buf = [0u8; CAP];
let buf = &mut buf[..len];
reader.read_exact(buf)?;
let s = str::from_utf8(&buf).map_err(|err| {
borsh::io::Error::new(borsh::io::ErrorKind::InvalidData, err.to_string())
})?;
Ok(Self::from(s).unwrap())
}
}
impl<'a, const CAP: usize> TryFrom<&'a str> for ArrayString<CAP>
{
type Error = CapacityError<&'a str>;

View File

@ -39,10 +39,11 @@ use crate::utils::MakeMaybeUninit;
///
/// It offers a simple API but also dereferences to a slice, so that the full slice API is
/// available. The ArrayVec can be converted into a by value iterator.
#[repr(C)]
pub struct ArrayVec<T, const CAP: usize> {
len: LenUint,
// the `len` first elements of the array are initialized
xs: [MaybeUninit<T>; CAP],
len: LenUint,
}
impl<T, const CAP: usize> Drop for ArrayVec<T, CAP> {
@ -879,6 +880,17 @@ pub struct IntoIter<T, const CAP: usize> {
index: usize,
v: ArrayVec<T, CAP>,
}
impl<T, const CAP: usize> IntoIter<T, CAP> {
/// Returns the remaining items of this iterator as a slice.
pub fn as_slice(&self) -> &[T] {
&self.v[self.index..]
}
/// Returns the remaining items of this iterator as a mutable slice.
pub fn as_mut_slice(&mut self) -> &mut [T] {
&mut self.v[self.index..]
}
}
impl<T, const CAP: usize> Iterator for IntoIter<T, CAP> {
type Item = T;
@ -1088,7 +1100,9 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
if let Some(elt) = iter.next() {
if ptr == end_ptr && CHECK { extend_panic(); }
debug_assert_ne!(ptr, end_ptr);
if mem::size_of::<T>() != 0 {
ptr.write(elt);
}
ptr = raw_ptr_add(ptr, 1);
guard.data += 1;
} else {
@ -1115,7 +1129,7 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
unsafe fn raw_ptr_add<T>(ptr: *mut T, offset: usize) -> *mut T {
if mem::size_of::<T>() == 0 {
// Special case for ZST
ptr.cast::<u8>().wrapping_add(offset).cast()
ptr.cast::<u8>().wrapping_add(offset).cast::<T>()
} else {
ptr.add(offset)
}
@ -1298,3 +1312,37 @@ impl<'de, T: Deserialize<'de>, const CAP: usize> Deserialize<'de> for ArrayVec<T
deserializer.deserialize_seq(ArrayVecVisitor::<T, CAP>(PhantomData))
}
}
#[cfg(feature = "borsh")]
/// Requires crate feature `"borsh"`
impl<T, const CAP: usize> borsh::BorshSerialize for ArrayVec<T, CAP>
where
T: borsh::BorshSerialize,
{
fn serialize<W: borsh::io::Write>(&self, writer: &mut W) -> borsh::io::Result<()> {
<[T] as borsh::BorshSerialize>::serialize(self.as_slice(), writer)
}
}
#[cfg(feature = "borsh")]
/// Requires crate feature `"borsh"`
impl<T, const CAP: usize> borsh::BorshDeserialize for ArrayVec<T, CAP>
where
T: borsh::BorshDeserialize,
{
fn deserialize_reader<R: borsh::io::Read>(reader: &mut R) -> borsh::io::Result<Self> {
let mut values = Self::new();
let len = <u32 as borsh::BorshDeserialize>::deserialize_reader(reader)?;
for _ in 0..len {
let elem = <T as borsh::BorshDeserialize>::deserialize_reader(reader)?;
if let Err(_) = values.try_push(elem) {
return Err(borsh::io::Error::new(
borsh::io::ErrorKind::InvalidData,
format!("Expected an array with no more than {} items", CAP),
));
}
}
Ok(values)
}
}

73
vendor/arrayvec/tests/borsh.rs vendored Normal file
View File

@ -0,0 +1,73 @@
#![cfg(feature = "borsh")]
use std::fmt;
extern crate arrayvec;
extern crate borsh;
fn assert_ser<T: borsh::BorshSerialize>(v: &T, expected_bytes: &[u8]) {
let mut actual_bytes = Vec::new();
v.serialize(&mut actual_bytes).unwrap();
assert_eq!(actual_bytes, expected_bytes);
}
fn assert_roundtrip<T: borsh::BorshSerialize + borsh::BorshDeserialize + PartialEq + fmt::Debug>(v: &T) {
let mut bytes = Vec::new();
v.serialize(&mut bytes).unwrap();
let v_de = T::try_from_slice(&bytes).unwrap();
assert_eq!(*v, v_de);
}
mod array_vec {
use arrayvec::ArrayVec;
use super::{assert_ser, assert_roundtrip};
#[test]
fn test_empty() {
let vec = ArrayVec::<u32, 0>::new();
assert_ser(&vec, b"\0\0\0\0");
assert_roundtrip(&vec);
}
#[test]
fn test_full() {
let mut vec = ArrayVec::<u32, 3>::new();
vec.push(0xdeadbeef);
vec.push(0x123);
vec.push(0x456);
assert_ser(&vec, b"\x03\0\0\0\xef\xbe\xad\xde\x23\x01\0\0\x56\x04\0\0");
assert_roundtrip(&vec);
}
#[test]
fn test_with_free_capacity() {
let mut vec = ArrayVec::<u32, 3>::new();
vec.push(0xdeadbeef);
assert_ser(&vec, b"\x01\0\0\0\xef\xbe\xad\xde");
assert_roundtrip(&vec);
}
}
mod array_string {
use arrayvec::ArrayString;
use super::{assert_ser, assert_roundtrip};
#[test]
fn test_empty() {
let string = ArrayString::<0>::new();
assert_ser(&string, b"\0\0\0\0");
assert_roundtrip(&string);
}
#[test]
fn test_full() {
let string = ArrayString::from_byte_string(b"hello world").unwrap();
assert_ser(&string, b"\x0b\0\0\0hello world");
assert_roundtrip(&string);
}
#[test]
fn test_with_free_capacity() {
let string = ArrayString::<16>::from("hello world").unwrap();
assert_ser(&string, b"\x0b\0\0\0hello world");
assert_roundtrip(&string);
}
}

View File

@ -695,20 +695,6 @@ fn test_default() {
assert_eq!(v.len(), 0);
}
#[cfg(feature="array-sizes-33-128")]
#[test]
fn test_sizes_33_128() {
ArrayVec::from([0u8; 52]);
ArrayVec::from([0u8; 127]);
}
#[cfg(feature="array-sizes-129-255")]
#[test]
fn test_sizes_129_255() {
ArrayVec::from([0u8; 237]);
ArrayVec::from([0u8; 255]);
}
#[test]
fn test_extend_zst() {
let mut range = 0..10;

View File

@ -1 +1 @@
{"files":{"Cargo.lock":"3d91565ed13de572a9ebde408a0c98e33f931d6ab52f212b0830a60b4ab26b77","Cargo.toml":"39f627122dceaad42146634719fde802fca3baa1b3908753af723074ae2a6d69","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"27995d58ad5c1145c1a8cd86244ce844886958a35eb2b78c6b772748669999ac","README.md":"4c8f9b5016f2a0c3dbeca5bc41241f57db5568f803e58c1fa480ae2b3638d0a9","examples/integers.rs":"589ff4271566dfa322becddf3e2c7b592e6e0bc97b02892ce75619b7e452e930","examples/paths.rs":"1b30e466b824ce8df7ad0a55334424131d9d2573d6cf9f7d5d50c09c8901d526","examples/traits.rs":"cbee6a3e1f7db60b02ae25b714926517144a77cb492021f492774cf0e1865a9e","examples/versions.rs":"38535e6d9f5bfae0de474a3db79a40e8f5da8ba9334c5ff4c363de9bc99d4d12","src/error.rs":"12de7dafea4a35d1dc2f0fa79bfa038386bbbea72bf083979f4ddf227999eeda","src/lib.rs":"6fa01458e8f9258d84f83ead24fdb0cdf9aec10838b0262f1dfbdf79c530c537","src/tests.rs":"f0e6dc1ad9223c0336c02e215ea3940acb2af6c3bc8fd791e16cd4e786e6a608","src/version.rs":"175727d5f02f2fe2271ddc9b041db2a5b9c6fe0f95afd17c73a4d982612764a3","tests/rustflags.rs":"5c8169b88216055019db61b5d7baf4abdf675e3b14b54f5037bb1e3acd0a5d3f"},"package":"d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"}
{"files":{"Cargo.lock":"c53e68eabea3d0b6dbc762cdc0c0bd105a7ac97c76e0b8c5f492d0b94074469c","Cargo.toml":"624e428251fce7244aa71fe7764c1556bc8077ee4579ad7e5803cc8a74061673","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"27995d58ad5c1145c1a8cd86244ce844886958a35eb2b78c6b772748669999ac","README.md":"21308cfaaea9e841e01a43b7ec77304c1daeea8d0e3ec8fe5022d8e56acc4eb2","examples/integers.rs":"589ff4271566dfa322becddf3e2c7b592e6e0bc97b02892ce75619b7e452e930","examples/nightly.rs":"ac8b5a9aa1e04465e44f5053b3c899b635e07af058c73aa8b45176bf4b5912f9","examples/paths.rs":"1b30e466b824ce8df7ad0a55334424131d9d2573d6cf9f7d5d50c09c8901d526","examples/traits.rs":"cbee6a3e1f7db60b02ae25b714926517144a77cb492021f492774cf0e1865a9e","examples/versions.rs":"38535e6d9f5bfae0de474a3db79a40e8f5da8ba9334c5ff4c363de9bc99d4d12","src/error.rs":"fd8ff67c64f7cd1b9f81325a81de4baa34c39d6ae298bdb33f9829cc91acac39","src/lib.rs":"b40828305eb18bcaad11608fbbf82d97fe381803fbf1b89a1511f0675ba49e6c","src/rustc.rs":"a8a213ddb64a05c1a1af933bcb331a98879e942b167c33d8f94f9f60ebb14e29","src/tests.rs":"b39f4d880ad343e65307a9e0c381954ea27adce4732f825516ce7952e2e5a91d","src/version.rs":"4f7d23b36f01c7be1871be86c038d6cb4689e145d67c82d3793690e9aa05b133","tests/no_std.rs":"18859dc4992fe1769887bde05f03d28f1ce524eafd17646d3fbcb4379422761a","tests/rustflags.rs":"e8ded4d57ba25379a38ab48456d67df14f82abbbb5f6bb66221c6decbcb517a3","tests/support/mod.rs":"32087d365b438ac3f62df9bb066d8d648b80cb130a5c777afcb2f21fbb68d88e","tests/tests.rs":"abd41a6a937ee58d7dcb541384705f87ec47294f6af6dab821441d50fd66ee7d","tests/wrap_ignored":"a9e241edf584a0702066b25bc15c5bbfd8a1019e14fb655fc4f47a67360065ca","tests/wrappers.rs":"b5137fe36768eaef277fb8650b0fe45b2c675d9e60b1b49d39f2ec95082c285b"},"package":"ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"}

5
vendor/autocfg/Cargo.lock generated vendored
View File

@ -1,7 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.1.0"
version = "1.4.0"

View File

@ -10,15 +10,66 @@
# See Cargo.toml.orig for the original contents.
[package]
rust-version = "1.0"
name = "autocfg"
version = "1.1.0"
version = "1.4.0"
authors = ["Josh Stone <cuviper@gmail.com>"]
exclude = ["/.github/**", "/bors.toml"]
build = false
exclude = ["/.github/**"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Automatic cfg for Rust compiler features"
documentation = "https://docs.rs/autocfg/"
readme = "README.md"
keywords = ["rustc", "build", "autoconf"]
keywords = [
"rustc",
"build",
"autoconf",
]
categories = ["development-tools::build-utils"]
license = "Apache-2.0 OR MIT"
repository = "https://github.com/cuviper/autocfg"
[lib]
name = "autocfg"
path = "src/lib.rs"
[[example]]
name = "integers"
path = "examples/integers.rs"
[[example]]
name = "nightly"
path = "examples/nightly.rs"
[[example]]
name = "paths"
path = "examples/paths.rs"
[[example]]
name = "traits"
path = "examples/traits.rs"
[[example]]
name = "versions"
path = "examples/versions.rs"
[[test]]
name = "no_std"
path = "tests/no_std.rs"
[[test]]
name = "rustflags"
path = "tests/rustflags.rs"
[[test]]
name = "tests"
path = "tests/tests.rs"
[[test]]
name = "wrappers"
path = "tests/wrappers.rs"
[dependencies]

View File

@ -43,6 +43,23 @@ should only be used when the compiler supports it.
## Release Notes
- 1.4.0 (2024-09-26)
- Add `emit_possibility` for Rust 1.80's [checked cfgs], and call that
automatically for methods that conditionally `emit`, by @Techcable.
[checked cfgs]: https://blog.rust-lang.org/2024/05/06/check-cfg.html
- 1.3.0 (2024-05-03)
- Add `probe_raw` for direct control of the code that will be test-compiled.
- Use wrappers when querying the `rustc` version information too.
- 1.2.0 (2024-03-25)
- Add `no_std` and `set_no_std` to control the use of `#![no_std]` in probes.
- Use `RUSTC_WRAPPER` and `RUSTC_WORKSPACE_WRAPPER` when they are set.
- 1.1.0 (2022-02-07)
- Use `CARGO_ENCODED_RUSTFLAGS` when it is set.
@ -88,8 +105,8 @@ treated as a major breaking change for semver purposes.
This project is licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
https://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)
https://opensource.org/licenses/MIT)
at your option.

18
vendor/autocfg/examples/nightly.rs vendored Normal file
View File

@ -0,0 +1,18 @@
extern crate autocfg;
fn main() {
// Normally, cargo will set `OUT_DIR` for build scripts.
let ac = autocfg::AutoCfg::with_dir("target").unwrap();
// When this feature was stabilized, it also renamed the method to
// `chunk_by`, so it's important to *use* the feature in your probe.
let code = r#"
#![feature(slice_group_by)]
pub fn probe(slice: &[i32]) -> impl Iterator<Item = &[i32]> {
slice.group_by(|a, b| a == b)
}
"#;
if ac.probe_raw(code).is_ok() {
autocfg::emit("has_slice_group_by");
}
}

View File

@ -2,6 +2,7 @@ use std::error;
use std::fmt;
use std::io;
use std::num;
use std::process;
use std::str;
/// A common error type for the `autocfg` crate.
@ -20,7 +21,7 @@ impl error::Error for Error {
ErrorKind::Io(ref e) => Some(e),
ErrorKind::Num(ref e) => Some(e),
ErrorKind::Utf8(ref e) => Some(e),
ErrorKind::Other(_) => None,
ErrorKind::Process(_) | ErrorKind::Other(_) => None,
}
}
}
@ -31,6 +32,10 @@ impl fmt::Display for Error {
ErrorKind::Io(ref e) => e.fmt(f),
ErrorKind::Num(ref e) => e.fmt(f),
ErrorKind::Utf8(ref e) => e.fmt(f),
ErrorKind::Process(ref status) => {
// Same message as the newer `ExitStatusError`
write!(f, "process exited unsuccessfully: {}", status)
}
ErrorKind::Other(s) => s.fmt(f),
}
}
@ -40,10 +45,17 @@ impl fmt::Display for Error {
enum ErrorKind {
Io(io::Error),
Num(num::ParseIntError),
Process(process::ExitStatus),
Utf8(str::Utf8Error),
Other(&'static str),
}
pub fn from_exit(status: process::ExitStatus) -> Error {
Error {
kind: ErrorKind::Process(status),
}
}
pub fn from_io(e: io::Error) -> Error {
Error {
kind: ErrorKind::Io(e),

View File

@ -20,7 +20,8 @@
//!
//! fn main() {
//! # // Normally, cargo will set `OUT_DIR` for build scripts.
//! # std::env::set_var("OUT_DIR", "target");
//! # let exe = std::env::current_exe().unwrap();
//! # std::env::set_var("OUT_DIR", exe.parent().unwrap());
//! let ac = autocfg::new();
//! ac.emit_has_type("i128");
//!
@ -61,10 +62,11 @@ macro_rules! try {
use std::env;
use std::ffi::OsString;
use std::fmt::Arguments;
use std::fs;
use std::io::{stderr, Write};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::process::Stdio;
#[allow(deprecated)]
use std::sync::atomic::ATOMIC_USIZE_INIT;
use std::sync::atomic::{AtomicUsize, Ordering};
@ -72,6 +74,9 @@ use std::sync::atomic::{AtomicUsize, Ordering};
mod error;
pub use error::Error;
mod rustc;
use rustc::Rustc;
mod version;
use version::Version;
@ -82,11 +87,12 @@ mod tests;
#[derive(Clone, Debug)]
pub struct AutoCfg {
out_dir: PathBuf,
rustc: PathBuf,
rustc: Rustc,
rustc_version: Version,
target: Option<OsString>,
no_std: bool,
rustflags: Vec<String>,
uuid: u64,
}
/// Writes a config flag for rustc on standard out.
@ -94,6 +100,12 @@ pub struct AutoCfg {
/// This looks like: `cargo:rustc-cfg=CFG`
///
/// Cargo will use this in arguments to rustc, like `--cfg CFG`.
///
/// This does not automatically call [`emit_possibility`]
/// so the compiler my generate an [`unexpected_cfgs` warning][check-cfg-flags].
/// However, all the builtin emit methods on [`AutoCfg`] call [`emit_possibility`] automatically.
///
/// [check-cfg-flags]: https://blog.rust-lang.org/2024/05/06/check-cfg.html
pub fn emit(cfg: &str) {
println!("cargo:rustc-cfg={}", cfg);
}
@ -119,7 +131,26 @@ pub fn rerun_env(var: &str) {
println!("cargo:rerun-if-env-changed={}", var);
}
/// Create a new `AutoCfg` instance.
/// Indicates to rustc that a config flag should not generate an [`unexpected_cfgs` warning][check-cfg-flags]
///
/// This looks like `cargo:rustc-check-cfg=cfg(VAR)`
///
/// As of rust 1.80, the compiler does [automatic checking of cfgs at compile time][check-cfg-flags].
/// All custom configuration flags must be known to rustc, or they will generate a warning.
/// This is done automatically when calling the builtin emit methods on [`AutoCfg`],
/// but not when calling [`autocfg::emit`](crate::emit) directly.
///
/// Versions before rust 1.80 will simply ignore this directive.
///
/// This function indicates to the compiler that the config flag never has a value.
/// If this is not desired, see [the blog post][check-cfg].
///
/// [check-cfg-flags]: https://blog.rust-lang.org/2024/05/06/check-cfg.html
pub fn emit_possibility(cfg: &str) {
println!("cargo:rustc-check-cfg=cfg({})", cfg);
}
/// Creates a new `AutoCfg` instance.
///
/// # Panics
///
@ -129,7 +160,7 @@ pub fn new() -> AutoCfg {
}
impl AutoCfg {
/// Create a new `AutoCfg` instance.
/// Creates a new `AutoCfg` instance.
///
/// # Common errors
///
@ -144,7 +175,7 @@ impl AutoCfg {
}
}
/// Create a new `AutoCfg` instance with the specified output directory.
/// Creates a new `AutoCfg` instance with the specified output directory.
///
/// # Common errors
///
@ -153,9 +184,8 @@ impl AutoCfg {
/// - `dir` is not a writable directory.
///
pub fn with_dir<T: Into<PathBuf>>(dir: T) -> Result<Self, Error> {
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
let rustc: PathBuf = rustc.into();
let rustc_version = try!(Version::from_rustc(&rustc));
let rustc = Rustc::new();
let rustc_version = try!(rustc.version());
let target = env::var_os("TARGET");
@ -173,14 +203,15 @@ impl AutoCfg {
rustc_version: rustc_version,
target: target,
no_std: false,
uuid: new_uuid(),
};
// Sanity check with and without `std`.
if !ac.probe("").unwrap_or(false) {
if !ac.probe_raw("").is_ok() {
if ac.probe_raw("#![no_std]").is_ok() {
ac.no_std = true;
if !ac.probe("").unwrap_or(false) {
} else {
// Neither worked, so assume nothing...
ac.no_std = false;
let warning = b"warning: autocfg could not probe for `std`\n";
stderr().write_all(warning).ok();
}
@ -188,7 +219,34 @@ impl AutoCfg {
Ok(ac)
}
/// Test whether the current `rustc` reports a version greater than
/// Returns whether `AutoCfg` is using `#![no_std]` in its probes.
///
/// This is automatically detected during construction -- if an empty probe
/// fails while one with `#![no_std]` succeeds, then the attribute will be
/// used for all further probes. This is usually only necessary when the
/// `TARGET` lacks `std` altogether. If neither succeeds, `no_std` is not
/// set, but that `AutoCfg` will probably only work for version checks.
///
/// This attribute changes the implicit [prelude] from `std` to `core`,
/// which may affect the paths you need to use in other probes. It also
/// restricts some types that otherwise get additional methods in `std`,
/// like floating-point trigonometry and slice sorting.
///
/// See also [`set_no_std`](#method.set_no_std).
///
/// [prelude]: https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute
pub fn no_std(&self) -> bool {
self.no_std
}
/// Sets whether `AutoCfg` should use `#![no_std]` in its probes.
///
/// See also [`no_std`](#method.no_std).
pub fn set_no_std(&mut self, no_std: bool) {
self.no_std = no_std;
}
/// Tests whether the current `rustc` reports a version greater than
/// or equal to "`major`.`minor`".
pub fn probe_rustc_version(&self, major: usize, minor: usize) -> bool {
self.rustc_version >= Version::new(major, minor, 0)
@ -197,20 +255,27 @@ impl AutoCfg {
/// Sets a `cfg` value of the form `rustc_major_minor`, like `rustc_1_29`,
/// if the current `rustc` is at least that version.
pub fn emit_rustc_version(&self, major: usize, minor: usize) {
let cfg_flag = format!("rustc_{}_{}", major, minor);
emit_possibility(&cfg_flag);
if self.probe_rustc_version(major, minor) {
emit(&format!("rustc_{}_{}", major, minor));
emit(&cfg_flag);
}
}
fn probe<T: AsRef<[u8]>>(&self, code: T) -> Result<bool, Error> {
/// Returns a new (hopefully unique) crate name for probes.
fn new_crate_name(&self) -> String {
#[allow(deprecated)]
static ID: AtomicUsize = ATOMIC_USIZE_INIT;
let id = ID.fetch_add(1, Ordering::Relaxed);
let mut command = Command::new(&self.rustc);
format!("autocfg_{:016x}_{}", self.uuid, id)
}
fn probe_fmt<'a>(&self, source: Arguments<'a>) -> Result<(), Error> {
let mut command = self.rustc.command();
command
.arg("--crate-name")
.arg(format!("probe{}", id))
.arg(self.new_crate_name())
.arg("--crate-type=lib")
.arg("--out-dir")
.arg(&self.out_dir)
@ -226,14 +291,71 @@ impl AutoCfg {
let mut child = try!(command.spawn().map_err(error::from_io));
let mut stdin = child.stdin.take().expect("rustc stdin");
if self.no_std {
try!(stdin.write_all(b"#![no_std]\n").map_err(error::from_io));
}
try!(stdin.write_all(code.as_ref()).map_err(error::from_io));
try!(stdin.write_fmt(source).map_err(error::from_io));
drop(stdin);
let status = try!(child.wait().map_err(error::from_io));
Ok(status.success())
match child.wait() {
Ok(status) if status.success() => Ok(()),
Ok(status) => Err(error::from_exit(status)),
Err(error) => Err(error::from_io(error)),
}
}
fn probe<'a>(&self, code: Arguments<'a>) -> bool {
let result = if self.no_std {
self.probe_fmt(format_args!("#![no_std]\n{}", code))
} else {
self.probe_fmt(code)
};
result.is_ok()
}
/// Tests whether the given code can be compiled as a Rust library.
///
/// This will only return `Ok` if the compiler ran and exited successfully,
/// per `ExitStatus::success()`.
/// The code is passed to the compiler exactly as-is, notably not even
/// adding the [`#![no_std]`][Self::no_std] attribute like other probes.
///
/// Raw probes are useful for testing functionality that's not yet covered
/// by the rest of the `AutoCfg` API. For example, the following attribute
/// **must** be used at the crate level, so it wouldn't work within the code
/// templates used by other `probe_*` methods.
///
/// ```
/// # extern crate autocfg;
/// # // Normally, cargo will set `OUT_DIR` for build scripts.
/// # let exe = std::env::current_exe().unwrap();
/// # std::env::set_var("OUT_DIR", exe.parent().unwrap());
/// let ac = autocfg::new();
/// assert!(ac.probe_raw("#![no_builtins]").is_ok());
/// ```
///
/// Rust nightly features could be tested as well -- ideally including a
/// code sample to ensure the unstable feature still works as expected.
/// For example, `slice::group_by` was renamed to `chunk_by` when it was
/// stabilized, even though the feature name was unchanged, so testing the
/// `#![feature(..)]` alone wouldn't reveal that. For larger snippets,
/// [`include_str!`] may be useful to load them from separate files.
///
/// ```
/// # extern crate autocfg;
/// # // Normally, cargo will set `OUT_DIR` for build scripts.
/// # let exe = std::env::current_exe().unwrap();
/// # std::env::set_var("OUT_DIR", exe.parent().unwrap());
/// let ac = autocfg::new();
/// let code = r#"
/// #![feature(slice_group_by)]
/// pub fn probe(slice: &[i32]) -> impl Iterator<Item = &[i32]> {
/// slice.group_by(|a, b| a == b)
/// }
/// "#;
/// if ac.probe_raw(code).is_ok() {
/// autocfg::emit("has_slice_group_by");
/// }
/// ```
pub fn probe_raw(&self, code: &str) -> Result<(), Error> {
self.probe_fmt(format_args!("{}", code))
}
/// Tests whether the given sysroot crate can be used.
@ -244,14 +366,16 @@ impl AutoCfg {
/// extern crate CRATE as probe;
/// ```
pub fn probe_sysroot_crate(&self, name: &str) -> bool {
self.probe(format!("extern crate {} as probe;", name)) // `as _` wasn't stabilized until Rust 1.33
.unwrap_or(false)
// Note: `as _` wasn't stabilized until Rust 1.33
self.probe(format_args!("extern crate {} as probe;", name))
}
/// Emits a config value `has_CRATE` if `probe_sysroot_crate` returns true.
pub fn emit_sysroot_crate(&self, name: &str) {
let cfg_flag = format!("has_{}", mangle(name));
emit_possibility(&cfg_flag);
if self.probe_sysroot_crate(name) {
emit(&format!("has_{}", mangle(name)));
emit(&cfg_flag);
}
}
@ -263,7 +387,7 @@ impl AutoCfg {
/// pub use PATH;
/// ```
pub fn probe_path(&self, path: &str) -> bool {
self.probe(format!("pub use {};", path)).unwrap_or(false)
self.probe(format_args!("pub use {};", path))
}
/// Emits a config value `has_PATH` if `probe_path` returns true.
@ -271,13 +395,12 @@ impl AutoCfg {
/// Any non-identifier characters in the `path` will be replaced with
/// `_` in the generated config value.
pub fn emit_has_path(&self, path: &str) {
if self.probe_path(path) {
emit(&format!("has_{}", mangle(path)));
}
self.emit_path_cfg(path, &format!("has_{}", mangle(path)));
}
/// Emits the given `cfg` value if `probe_path` returns true.
pub fn emit_path_cfg(&self, path: &str, cfg: &str) {
emit_possibility(cfg);
if self.probe_path(path) {
emit(cfg);
}
@ -291,8 +414,7 @@ impl AutoCfg {
/// pub trait Probe: TRAIT + Sized {}
/// ```
pub fn probe_trait(&self, name: &str) -> bool {
self.probe(format!("pub trait Probe: {} + Sized {{}}", name))
.unwrap_or(false)
self.probe(format_args!("pub trait Probe: {} + Sized {{}}", name))
}
/// Emits a config value `has_TRAIT` if `probe_trait` returns true.
@ -300,13 +422,12 @@ impl AutoCfg {
/// Any non-identifier characters in the trait `name` will be replaced with
/// `_` in the generated config value.
pub fn emit_has_trait(&self, name: &str) {
if self.probe_trait(name) {
emit(&format!("has_{}", mangle(name)));
}
self.emit_trait_cfg(name, &format!("has_{}", mangle(name)));
}
/// Emits the given `cfg` value if `probe_trait` returns true.
pub fn emit_trait_cfg(&self, name: &str, cfg: &str) {
emit_possibility(cfg);
if self.probe_trait(name) {
emit(cfg);
}
@ -320,8 +441,7 @@ impl AutoCfg {
/// pub type Probe = TYPE;
/// ```
pub fn probe_type(&self, name: &str) -> bool {
self.probe(format!("pub type Probe = {};", name))
.unwrap_or(false)
self.probe(format_args!("pub type Probe = {};", name))
}
/// Emits a config value `has_TYPE` if `probe_type` returns true.
@ -329,13 +449,12 @@ impl AutoCfg {
/// Any non-identifier characters in the type `name` will be replaced with
/// `_` in the generated config value.
pub fn emit_has_type(&self, name: &str) {
if self.probe_type(name) {
emit(&format!("has_{}", mangle(name)));
}
self.emit_type_cfg(name, &format!("has_{}", mangle(name)));
}
/// Emits the given `cfg` value if `probe_type` returns true.
pub fn emit_type_cfg(&self, name: &str, cfg: &str) {
emit_possibility(cfg);
if self.probe_type(name) {
emit(cfg);
}
@ -349,12 +468,12 @@ impl AutoCfg {
/// pub fn probe() { let _ = EXPR; }
/// ```
pub fn probe_expression(&self, expr: &str) -> bool {
self.probe(format!("pub fn probe() {{ let _ = {}; }}", expr))
.unwrap_or(false)
self.probe(format_args!("pub fn probe() {{ let _ = {}; }}", expr))
}
/// Emits the given `cfg` value if `probe_expression` returns true.
pub fn emit_expression_cfg(&self, expr: &str, cfg: &str) {
emit_possibility(cfg);
if self.probe_expression(expr) {
emit(cfg);
}
@ -368,12 +487,12 @@ impl AutoCfg {
/// pub const PROBE: () = ((), EXPR).0;
/// ```
pub fn probe_constant(&self, expr: &str) -> bool {
self.probe(format!("pub const PROBE: () = ((), {}).0;", expr))
.unwrap_or(false)
self.probe(format_args!("pub const PROBE: () = ((), {}).0;", expr))
}
/// Emits the given `cfg` value if `probe_constant` returns true.
pub fn emit_constant_cfg(&self, expr: &str, cfg: &str) {
emit_possibility(cfg);
if self.probe_constant(expr) {
emit(cfg);
}
@ -405,7 +524,7 @@ fn dir_contains_target(
cargo_target_dir
.to_str()
.map(|cargo_target_dir| dir.contains(&cargo_target_dir))
.map(|cargo_target_dir| dir.contains(cargo_target_dir))
})
})
.unwrap_or(false)
@ -451,3 +570,21 @@ fn rustflags(target: &Option<OsString>, dir: &Path) -> Vec<String> {
Vec::new()
}
/// Generates a numeric ID to use in probe crate names.
///
/// This attempts to be random, within the constraints of Rust 1.0 and no dependencies.
fn new_uuid() -> u64 {
const FNV_OFFSET_BASIS: u64 = 0xcbf2_9ce4_8422_2325;
const FNV_PRIME: u64 = 0x100_0000_01b3;
// This set should have an actual random hasher.
let set: std::collections::HashSet<u64> = (0..256).collect();
// Feed the `HashSet`-shuffled order into FNV-1a.
let mut hash: u64 = FNV_OFFSET_BASIS;
for x in set {
hash = (hash ^ x).wrapping_mul(FNV_PRIME);
}
hash
}

89
vendor/autocfg/src/rustc.rs vendored Normal file
View File

@ -0,0 +1,89 @@
use std::env;
use std::ffi::OsString;
use std::path::PathBuf;
use std::process::Command;
use super::error::Error;
use super::version::Version;
#[derive(Clone, Debug)]
pub struct Rustc {
rustc: PathBuf,
rustc_wrapper: Option<PathBuf>,
rustc_workspace_wrapper: Option<PathBuf>,
}
impl Rustc {
pub fn new() -> Self {
Rustc {
rustc: env::var_os("RUSTC")
.unwrap_or_else(|| "rustc".into())
.into(),
rustc_wrapper: get_rustc_wrapper(false),
rustc_workspace_wrapper: get_rustc_wrapper(true),
}
}
/// Build the command with possible wrappers.
pub fn command(&self) -> Command {
let mut rustc = self
.rustc_wrapper
.iter()
.chain(self.rustc_workspace_wrapper.iter())
.chain(Some(&self.rustc));
let mut command = Command::new(rustc.next().unwrap());
for arg in rustc {
command.arg(arg);
}
command
}
/// Try to get the `rustc` version.
pub fn version(&self) -> Result<Version, Error> {
// Some wrappers like clippy-driver don't pass through version commands,
// so we try to fall back to combinations without each wrapper.
macro_rules! try_version {
($command:expr) => {
if let Ok(value) = Version::from_command($command) {
return Ok(value);
}
};
}
let rustc = &self.rustc;
if let Some(ref rw) = self.rustc_wrapper {
if let Some(ref rww) = self.rustc_workspace_wrapper {
try_version!(Command::new(rw).args(&[rww, rustc]));
}
try_version!(Command::new(rw).arg(rustc));
}
if let Some(ref rww) = self.rustc_workspace_wrapper {
try_version!(Command::new(rww).arg(rustc));
}
Version::from_command(&mut Command::new(rustc))
}
}
fn get_rustc_wrapper(workspace: bool) -> Option<PathBuf> {
// We didn't really know whether the workspace wrapper is applicable until Cargo started
// deliberately setting or unsetting it in rust-lang/cargo#9601. We'll use the encoded
// rustflags as a proxy for that change for now, but we could instead check version 1.55.
if workspace && env::var_os("CARGO_ENCODED_RUSTFLAGS").is_none() {
return None;
}
let name = if workspace {
"RUSTC_WORKSPACE_WRAPPER"
} else {
"RUSTC_WRAPPER"
};
if let Some(wrapper) = env::var_os(name) {
// NB: `OsStr` didn't get `len` or `is_empty` until 1.9.
if wrapper != OsString::new() {
return Some(wrapper.into());
}
}
None
}

View File

@ -1,36 +1,5 @@
use super::AutoCfg;
use std::env;
use std::path::Path;
impl AutoCfg {
fn core_std(&self, path: &str) -> String {
let krate = if self.no_std { "core" } else { "std" };
format!("{}::{}", krate, path)
}
fn assert_std(&self, probe_result: bool) {
assert_eq!(!self.no_std, probe_result);
}
fn assert_min(&self, major: usize, minor: usize, probe_result: bool) {
assert_eq!(self.probe_rustc_version(major, minor), probe_result);
}
fn for_test() -> Result<Self, super::error::Error> {
match env::var_os("TESTS_TARGET_DIR") {
Some(d) => Self::with_dir(d),
None => Self::with_dir("target"),
}
}
}
#[test]
fn autocfg_version() {
let ac = AutoCfg::for_test().unwrap();
println!("version: {:?}", ac.rustc_version);
assert!(ac.probe_rustc_version(1, 0));
}
#[test]
fn version_cmp() {
use super::version::Version;
@ -44,95 +13,6 @@ fn version_cmp() {
assert!(Version::new(2, 0, 0) > v123);
}
#[test]
fn probe_add() {
let ac = AutoCfg::for_test().unwrap();
let add = ac.core_std("ops::Add");
let add_rhs = add.clone() + "<i32>";
let add_rhs_output = add.clone() + "<i32, Output = i32>";
let dyn_add_rhs_output = "dyn ".to_string() + &*add_rhs_output;
assert!(ac.probe_path(&add));
assert!(ac.probe_trait(&add));
assert!(ac.probe_trait(&add_rhs));
assert!(ac.probe_trait(&add_rhs_output));
ac.assert_min(1, 27, ac.probe_type(&dyn_add_rhs_output));
}
#[test]
fn probe_as_ref() {
let ac = AutoCfg::for_test().unwrap();
let as_ref = ac.core_std("convert::AsRef");
let as_ref_str = as_ref.clone() + "<str>";
let dyn_as_ref_str = "dyn ".to_string() + &*as_ref_str;
assert!(ac.probe_path(&as_ref));
assert!(ac.probe_trait(&as_ref_str));
assert!(ac.probe_type(&as_ref_str));
ac.assert_min(1, 27, ac.probe_type(&dyn_as_ref_str));
}
#[test]
fn probe_i128() {
let ac = AutoCfg::for_test().unwrap();
let i128_path = ac.core_std("i128");
ac.assert_min(1, 26, ac.probe_path(&i128_path));
ac.assert_min(1, 26, ac.probe_type("i128"));
}
#[test]
fn probe_sum() {
let ac = AutoCfg::for_test().unwrap();
let sum = ac.core_std("iter::Sum");
let sum_i32 = sum.clone() + "<i32>";
let dyn_sum_i32 = "dyn ".to_string() + &*sum_i32;
ac.assert_min(1, 12, ac.probe_path(&sum));
ac.assert_min(1, 12, ac.probe_trait(&sum));
ac.assert_min(1, 12, ac.probe_trait(&sum_i32));
ac.assert_min(1, 12, ac.probe_type(&sum_i32));
ac.assert_min(1, 27, ac.probe_type(&dyn_sum_i32));
}
#[test]
fn probe_std() {
let ac = AutoCfg::for_test().unwrap();
ac.assert_std(ac.probe_sysroot_crate("std"));
}
#[test]
fn probe_alloc() {
let ac = AutoCfg::for_test().unwrap();
ac.assert_min(1, 36, ac.probe_sysroot_crate("alloc"));
}
#[test]
fn probe_bad_sysroot_crate() {
let ac = AutoCfg::for_test().unwrap();
assert!(!ac.probe_sysroot_crate("doesnt_exist"));
}
#[test]
fn probe_no_std() {
let ac = AutoCfg::for_test().unwrap();
assert!(ac.probe_type("i32"));
assert!(ac.probe_type("[i32]"));
ac.assert_std(ac.probe_type("Vec<i32>"));
}
#[test]
fn probe_expression() {
let ac = AutoCfg::for_test().unwrap();
assert!(ac.probe_expression(r#""test".trim_left()"#));
ac.assert_min(1, 30, ac.probe_expression(r#""test".trim_start()"#));
ac.assert_std(ac.probe_expression("[1, 2, 3].to_vec()"));
}
#[test]
fn probe_constant() {
let ac = AutoCfg::for_test().unwrap();
assert!(ac.probe_constant("1 + 2 + 3"));
ac.assert_min(1, 33, ac.probe_constant("{ let x = 1 + 2 + 3; x * x }"));
ac.assert_min(1, 39, ac.probe_constant(r#""test".len()"#));
}
#[test]
fn dir_does_not_contain_target() {
assert!(!super::dir_contains_target(

View File

@ -1,4 +1,3 @@
use std::path::Path;
use std::process::Command;
use std::str;
@ -22,9 +21,9 @@ impl Version {
}
}
pub fn from_rustc(rustc: &Path) -> Result<Self, Error> {
pub fn from_command(command: &mut Command) -> Result<Self, Error> {
// Get rustc's verbose version
let output = try!(Command::new(rustc)
let output = try!(command
.args(&["--version", "--verbose"])
.output()
.map_err(error::from_io));
@ -47,9 +46,15 @@ impl Version {
// Split the version into semver components.
let mut iter = version.splitn(3, '.');
let major = try!(iter.next().ok_or(error::from_str("missing major version")));
let minor = try!(iter.next().ok_or(error::from_str("missing minor version")));
let patch = try!(iter.next().ok_or(error::from_str("missing patch version")));
let major = try!(iter
.next()
.ok_or_else(|| error::from_str("missing major version")));
let minor = try!(iter
.next()
.ok_or_else(|| error::from_str("missing minor version")));
let patch = try!(iter
.next()
.ok_or_else(|| error::from_str("missing patch version")));
Ok(Version::new(
try!(major.parse().map_err(error::from_num)),

28
vendor/autocfg/tests/no_std.rs vendored Normal file
View File

@ -0,0 +1,28 @@
extern crate autocfg;
use std::env;
mod support;
/// Tests that we can control the use of `#![no_std]`.
#[test]
fn no_std() {
// Clear the CI `TARGET`, if any, so we're just dealing with the
// host target which always has `std` available.
env::remove_var("TARGET");
// Use the same path as this test binary.
let out = support::out_dir();
let mut ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
assert!(!ac.no_std());
assert!(ac.probe_path("std::mem"));
// `#![no_std]` was stabilized in Rust 1.6
if ac.probe_rustc_version(1, 6) {
ac.set_no_std(true);
assert!(ac.no_std());
assert!(!ac.probe_path("std::mem"));
assert!(ac.probe_path("core::mem"));
}
}

View File

@ -2,18 +2,19 @@ extern crate autocfg;
use std::env;
mod support;
/// Tests that autocfg uses the RUSTFLAGS or CARGO_ENCODED_RUSTFLAGS
/// environment variables when running rustc.
#[test]
fn test_with_sysroot() {
// Use the same path as this test binary.
let dir = env::current_exe().unwrap().parent().unwrap().to_path_buf();
env::set_var("OUT_DIR", &format!("{}", dir.display()));
let dir = support::exe_dir();
let out = support::out_dir();
// If we have encoded rustflags, they take precedence, even if empty.
env::set_var("CARGO_ENCODED_RUSTFLAGS", "");
env::set_var("RUSTFLAGS", &format!("-L {}", dir.display()));
let ac = autocfg::AutoCfg::new().unwrap();
let ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
assert!(ac.probe_sysroot_crate("std"));
assert!(!ac.probe_sysroot_crate("autocfg"));
@ -22,12 +23,12 @@ fn test_with_sysroot() {
"CARGO_ENCODED_RUSTFLAGS",
&format!("-L\x1f{}", dir.display()),
);
let ac = autocfg::AutoCfg::new().unwrap();
let ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
assert!(ac.probe_sysroot_crate("autocfg"));
// Try the old-style RUSTFLAGS, ensuring HOST != TARGET.
env::remove_var("CARGO_ENCODED_RUSTFLAGS");
env::set_var("HOST", "lol");
let ac = autocfg::AutoCfg::new().unwrap();
let ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
assert!(ac.probe_sysroot_crate("autocfg"));
}

21
vendor/autocfg/tests/support/mod.rs vendored Normal file
View File

@ -0,0 +1,21 @@
use std::borrow::Cow;
use std::env;
use std::path::{Path, PathBuf};
/// The directory containing this test binary.
pub fn exe_dir() -> PathBuf {
let exe = env::current_exe().unwrap();
exe.parent().unwrap().to_path_buf()
}
/// The directory to use for test probes.
pub fn out_dir() -> Cow<'static, Path> {
if let Some(tmpdir) = option_env!("CARGO_TARGET_TMPDIR") {
Cow::Borrowed(tmpdir.as_ref())
} else if let Some(tmpdir) = env::var_os("TESTS_TARGET_DIR") {
Cow::Owned(tmpdir.into())
} else {
// Use the same path as this test binary.
Cow::Owned(exe_dir())
}
}

138
vendor/autocfg/tests/tests.rs vendored Normal file
View File

@ -0,0 +1,138 @@
extern crate autocfg;
use autocfg::AutoCfg;
mod support;
fn core_std(ac: &AutoCfg, path: &str) -> String {
let krate = if ac.no_std() { "core" } else { "std" };
format!("{}::{}", krate, path)
}
fn assert_std(ac: &AutoCfg, probe_result: bool) {
assert_eq!(!ac.no_std(), probe_result);
}
fn assert_min(ac: &AutoCfg, major: usize, minor: usize, probe_result: bool) {
assert_eq!(ac.probe_rustc_version(major, minor), probe_result);
}
fn autocfg_for_test() -> AutoCfg {
AutoCfg::with_dir(support::out_dir().as_ref()).unwrap()
}
#[test]
fn autocfg_version() {
let ac = autocfg_for_test();
assert!(ac.probe_rustc_version(1, 0));
}
#[test]
fn probe_add() {
let ac = autocfg_for_test();
let add = core_std(&ac, "ops::Add");
let add_rhs = add.clone() + "<i32>";
let add_rhs_output = add.clone() + "<i32, Output = i32>";
let dyn_add_rhs_output = "dyn ".to_string() + &*add_rhs_output;
assert!(ac.probe_path(&add));
assert!(ac.probe_trait(&add));
assert!(ac.probe_trait(&add_rhs));
assert!(ac.probe_trait(&add_rhs_output));
assert_min(&ac, 1, 27, ac.probe_type(&dyn_add_rhs_output));
}
#[test]
fn probe_as_ref() {
let ac = autocfg_for_test();
let as_ref = core_std(&ac, "convert::AsRef");
let as_ref_str = as_ref.clone() + "<str>";
let dyn_as_ref_str = "dyn ".to_string() + &*as_ref_str;
assert!(ac.probe_path(&as_ref));
assert!(ac.probe_trait(&as_ref_str));
assert!(ac.probe_type(&as_ref_str));
assert_min(&ac, 1, 27, ac.probe_type(&dyn_as_ref_str));
}
#[test]
fn probe_i128() {
let ac = autocfg_for_test();
let i128_path = core_std(&ac, "i128");
assert_min(&ac, 1, 26, ac.probe_path(&i128_path));
assert_min(&ac, 1, 26, ac.probe_type("i128"));
}
#[test]
fn probe_sum() {
let ac = autocfg_for_test();
let sum = core_std(&ac, "iter::Sum");
let sum_i32 = sum.clone() + "<i32>";
let dyn_sum_i32 = "dyn ".to_string() + &*sum_i32;
assert_min(&ac, 1, 12, ac.probe_path(&sum));
assert_min(&ac, 1, 12, ac.probe_trait(&sum));
assert_min(&ac, 1, 12, ac.probe_trait(&sum_i32));
assert_min(&ac, 1, 12, ac.probe_type(&sum_i32));
assert_min(&ac, 1, 27, ac.probe_type(&dyn_sum_i32));
}
#[test]
fn probe_std() {
let ac = autocfg_for_test();
assert_std(&ac, ac.probe_sysroot_crate("std"));
}
#[test]
fn probe_alloc() {
let ac = autocfg_for_test();
assert_min(&ac, 1, 36, ac.probe_sysroot_crate("alloc"));
}
#[test]
fn probe_bad_sysroot_crate() {
let ac = autocfg_for_test();
assert!(!ac.probe_sysroot_crate("doesnt_exist"));
}
#[test]
fn probe_no_std() {
let ac = autocfg_for_test();
assert!(ac.probe_type("i32"));
assert!(ac.probe_type("[i32]"));
assert_std(&ac, ac.probe_type("Vec<i32>"));
}
#[test]
fn probe_expression() {
let ac = autocfg_for_test();
assert!(ac.probe_expression(r#""test".trim_left()"#));
assert_min(&ac, 1, 30, ac.probe_expression(r#""test".trim_start()"#));
assert_std(&ac, ac.probe_expression("[1, 2, 3].to_vec()"));
}
#[test]
fn probe_constant() {
let ac = autocfg_for_test();
assert!(ac.probe_constant("1 + 2 + 3"));
assert_min(
&ac,
1,
33,
ac.probe_constant("{ let x = 1 + 2 + 3; x * x }"),
);
assert_min(&ac, 1, 39, ac.probe_constant(r#""test".len()"#));
}
#[test]
fn probe_raw() {
let ac = autocfg_for_test();
let prefix = if ac.no_std() { "#![no_std]\n" } else { "" };
let f = |s| format!("{}{}", prefix, s);
// This attribute **must** be used at the crate level.
assert!(ac.probe_raw(&f("#![no_builtins]")).is_ok());
assert!(ac.probe_raw(&f("#![deny(dead_code)] fn x() {}")).is_err());
assert!(ac.probe_raw(&f("#![allow(dead_code)] fn x() {}")).is_ok());
assert!(ac
.probe_raw(&f("#![deny(dead_code)] pub fn x() {}"))
.is_ok());
}

12
vendor/autocfg/tests/wrap_ignored vendored Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
for arg in "$@"; do
case "$arg" in
# Add our own version so we can check that the wrapper is used for that.
"--version") echo "release: 12345.6789.0" ;;
# Read all input so the writer doesn't get EPIPE when we exit.
"-") read -d "" PROBE ;;
esac
done
exit 0

56
vendor/autocfg/tests/wrappers.rs vendored Normal file
View File

@ -0,0 +1,56 @@
extern crate autocfg;
use std::env;
mod support;
/// Tests that autocfg uses the RUSTC_WRAPPER and/or RUSTC_WORKSPACE_WRAPPER
/// environment variables when running rustc.
#[test]
#[cfg(unix)] // we're using system binaries as wrappers
fn test_wrappers() {
fn set(name: &str, value: Option<bool>) {
match value {
Some(true) => env::set_var(name, "/usr/bin/env"),
Some(false) => env::set_var(name, "/bin/false"),
None => env::remove_var(name),
}
}
let out = support::out_dir();
// This is used as a heuristic to detect rust-lang/cargo#9601.
env::set_var("CARGO_ENCODED_RUSTFLAGS", "");
// No wrapper, a good pass-through wrapper, and a bad wrapper.
let variants = [None, Some(true), Some(false)];
for &workspace in &variants {
for &rustc in &variants {
set("RUSTC_WRAPPER", rustc);
set("RUSTC_WORKSPACE_WRAPPER", workspace);
let ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
if rustc == Some(false) || workspace == Some(false) {
// Everything should fail with bad wrappers.
assert!(!ac.probe_type("usize"));
} else {
// Try known good and bad types for the wrapped rustc.
assert!(ac.probe_type("usize"));
assert!(!ac.probe_type("mesize"));
}
// Either way, we should have found the inner rustc version.
assert!(ac.probe_rustc_version(1, 0));
}
}
// Finally, make sure that `RUSTC_WRAPPER` is applied outermost
// by using something that doesn't pass through at all.
env::set_var("RUSTC_WRAPPER", "./tests/wrap_ignored");
env::set_var("RUSTC_WORKSPACE_WRAPPER", "/bin/false");
let ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
assert!(ac.probe_type("mesize")); // anything goes!
// Make sure we also got the version from that wrapper.
assert!(ac.probe_rustc_version(12345, 6789));
}

View File

@ -1 +1 @@
{"files":{"Cargo.lock":"04119886c04657679f79427677471fab073335384cd4e5ede1befe99b7aec300","Cargo.toml":"41869f30ce812dad96a208097c5841a34b4d6293a1af551ad9c31b0011985ed4","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0dd882e53de11566d50f8e8e2d5a651bcf3fabee4987d70f306233cf39094ba7","README.md":"df01f5b4317d601e7de86743f9818aec9196abf9e298f5e47679b7a966ecd945","RELEASE-NOTES.md":"f3e29048ac678fce2131201ebfb81892752ed399bffe62ba28ef9602d029fce3","benches/benchmarks.rs":"cebbcc8649e760e569c6be04f5e727aee2c2568ced7faab580fc0aa0d0426d26","clippy.toml":"b26be4d15ed059985ce6994f11817fd7562046f46e460a0dc64dbb71cfc246d1","examples/base64.rs":"b75ead2199a9b4389c69fe6f1ae988176a263b8fc84e7a4fea1d7e5a41592078","icon_CLion.svg":"cffa044ba75cb998ee3306991dc4a3755ec2f39ab95ddd4b74bc21988389020f","src/alphabet.rs":"3461a34bd63c10cfe232deb5dd42e2ec2dfb5decd508caf31ec2a1826ad68131","src/chunked_encoder.rs":"edfdbb9a4329b80fb2c769ada81e234e00839e0fa85faaa70bacf40ce12e951c","src/decode.rs":"b046a72d62eaac58dc42efcf7848d9d96d022f6594e851cf87074b77ce45c04a","src/display.rs":"31bf3e19274a0b80dd8948a81ea535944f756ef5b88736124c940f5fe1e8c71c","src/encode.rs":"44ddcc162f3fe9817b6e857dda0a3b9197b90a657e5f71c44aacabf5431ccf7d","src/engine/general_purpose/decode.rs":"d865b057e5788e7fefd189cf57ec913df263e6a0742dfa52513f587e14fa1a92","src/engine/general_purpose/decode_suffix.rs":"689688f7bf442b232d3b9f56a1b41c56d9393ace88556a165c224b93dd19b74e","src/engine/general_purpose/mod.rs":"901760a7f5721ec3bafad5fea6251f57de0f767ecb2e1e2fdfe64d661404ec34","src/engine/mod.rs":"e3b0ae19ff8e89ed247ac4f370f300882ad2991d2b8d2ae12f827fa83b13487a","src/engine/naive.rs":"70de29d909c3fe7918d2965782088b05047b8b6e30d1d2bf11ba073d3f8633ff","src/engine/tests.rs":"2cc8d1431f40f5b9c3ad8970e6fb73bba8be3f2317553dd026539f41908aaa19","src/lib.rs":"c4db7bd31ace78aec2ecd151cef3ad90dfdc76097ba12027bde79d3c82612f7c","src/prelude.rs":"c1587138e5301ac797c5c362cb3638649b33f79c20c16db6f38ad44330540752","src/read/decoder.rs":"00aaa0553a54fcf12762658c4e56663a9705cc30c07af30976291e6f69d78c3d","src/read/decoder_tests.rs":"edeee377e70095532be1625d0148de2273b739e9069a05e616d3e67877d92f1d","src/read/mod.rs":"e0b714eda02d16b1ffa6f78fd09b2f963e01c881b1f7c17b39db4e904be5e746","src/tests.rs":"90cb9f8a1ccb7c4ddc4f8618208e0031fc97e0df0e5aa466d6a5cf45d25967d8","src/write/encoder.rs":"c889c853249220fe2ddaeb77ee6e2ee2945f7db88cd6658ef89ff71b81255ea8","src/write/encoder_string_writer.rs":"0326c9d120369b9bbc35697b5b9b141bed24283374c93d5af1052eb042e47799","src/write/encoder_tests.rs":"28695a485b17cf5db73656aae5d90127f726e02c6d70efd83e5ab53a4cc17b38","src/write/mod.rs":"73cd98dadc9d712b3fefd9449d97e825e097397441b90588e0051e4d3b0911b9","tests/encode.rs":"5309f4538b1df611436f7bfba7409c725161b6f841b1bbf8d9890ae185de7d88","tests/tests.rs":"78efcf0dc4bb6ae52f7a91fcad89e44e4dce578224c36b4e6c1c306459be8500"},"package":"9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51"}
{"files":{"Cargo.lock":"cee37732975a1ffc1f956d3d05b6edf1baec72841cfabc384a21b02b3bfa0275","Cargo.toml":"52bee6a418e14918d37058fd15fccfd0f417a06fe4f9668b6f97866bf7f991e3","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0dd882e53de11566d50f8e8e2d5a651bcf3fabee4987d70f306233cf39094ba7","README.md":"df01f5b4317d601e7de86743f9818aec9196abf9e298f5e47679b7a966ecd945","RELEASE-NOTES.md":"997a5193317a8bff266ecfe4f015ba070b782b6df7d3a1738b9b52584d57f9c6","benches/benchmarks.rs":"cebbcc8649e760e569c6be04f5e727aee2c2568ced7faab580fc0aa0d0426d26","clippy.toml":"b26be4d15ed059985ce6994f11817fd7562046f46e460a0dc64dbb71cfc246d1","examples/base64.rs":"b75ead2199a9b4389c69fe6f1ae988176a263b8fc84e7a4fea1d7e5a41592078","icon_CLion.svg":"cffa044ba75cb998ee3306991dc4a3755ec2f39ab95ddd4b74bc21988389020f","src/alphabet.rs":"5de2beb8fcccb078c61cac2c0477ebbde145122d6c10a0f7ea2e57e8159318e0","src/chunked_encoder.rs":"edfdbb9a4329b80fb2c769ada81e234e00839e0fa85faaa70bacf40ce12e951c","src/decode.rs":"b046a72d62eaac58dc42efcf7848d9d96d022f6594e851cf87074b77ce45c04a","src/display.rs":"31bf3e19274a0b80dd8948a81ea535944f756ef5b88736124c940f5fe1e8c71c","src/encode.rs":"44ddcc162f3fe9817b6e857dda0a3b9197b90a657e5f71c44aacabf5431ccf7d","src/engine/general_purpose/decode.rs":"d865b057e5788e7fefd189cf57ec913df263e6a0742dfa52513f587e14fa1a92","src/engine/general_purpose/decode_suffix.rs":"689688f7bf442b232d3b9f56a1b41c56d9393ace88556a165c224b93dd19b74e","src/engine/general_purpose/mod.rs":"901760a7f5721ec3bafad5fea6251f57de0f767ecb2e1e2fdfe64d661404ec34","src/engine/mod.rs":"5e4a6c0e86417f3b62350264ef383f91e9864390f7c315d786ecd8e9c920ee9f","src/engine/naive.rs":"70de29d909c3fe7918d2965782088b05047b8b6e30d1d2bf11ba073d3f8633ff","src/engine/tests.rs":"2cc8d1431f40f5b9c3ad8970e6fb73bba8be3f2317553dd026539f41908aaa19","src/lib.rs":"c4db7bd31ace78aec2ecd151cef3ad90dfdc76097ba12027bde79d3c82612f7c","src/prelude.rs":"c1587138e5301ac797c5c362cb3638649b33f79c20c16db6f38ad44330540752","src/read/decoder.rs":"00aaa0553a54fcf12762658c4e56663a9705cc30c07af30976291e6f69d78c3d","src/read/decoder_tests.rs":"66ec39bf6e86f21f4db1afd6c5cd63d4a4931ab896b9c38de25d99b803804bbf","src/read/mod.rs":"e0b714eda02d16b1ffa6f78fd09b2f963e01c881b1f7c17b39db4e904be5e746","src/tests.rs":"90cb9f8a1ccb7c4ddc4f8618208e0031fc97e0df0e5aa466d6a5cf45d25967d8","src/write/encoder.rs":"c889c853249220fe2ddaeb77ee6e2ee2945f7db88cd6658ef89ff71b81255ea8","src/write/encoder_string_writer.rs":"0326c9d120369b9bbc35697b5b9b141bed24283374c93d5af1052eb042e47799","src/write/encoder_tests.rs":"28695a485b17cf5db73656aae5d90127f726e02c6d70efd83e5ab53a4cc17b38","src/write/mod.rs":"73cd98dadc9d712b3fefd9449d97e825e097397441b90588e0051e4d3b0911b9","tests/encode.rs":"5309f4538b1df611436f7bfba7409c725161b6f841b1bbf8d9890ae185de7d88","tests/tests.rs":"78efcf0dc4bb6ae52f7a91fcad89e44e4dce578224c36b4e6c1c306459be8500"},"package":"72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"}

4
vendor/base64/Cargo.lock generated vendored
View File

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "anes"
version = "0.1.6"
@ -186,7 +188,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "base64"
version = "0.22.0"
version = "0.22.1"
dependencies = [
"clap",
"criterion",

View File

@ -13,11 +13,8 @@
edition = "2018"
rust-version = "1.48.0"
name = "base64"
version = "0.22.0"
authors = [
"Alice Maz <alice@alicemaz.com>",
"Marshall Pierce <marshall@mpierce.org>",
]
version = "0.22.1"
authors = ["Marshall Pierce <marshall@mpierce.org>"]
description = "encodes and decodes base64 as bytes or utf8"
documentation = "https://docs.rs/base64"
readme = "README.md"

View File

@ -1,3 +1,7 @@
# 0.22.1
- Correct the symbols used for the predefined `alphabet::BIN_HEX`.
# 0.22.0
- `DecodeSliceError::OutputSliceTooSmall` is now conservative rather than precise. That is, the error will only occur if the decoded output _cannot_ fit, meaning that `Engine::decode_slice` can now be used with exactly-sized output slices. As part of this, `Engine::internal_decode` now returns `DecodeSliceError` instead of `DecodeError`, but that is not expected to affect any external callers.

View File

@ -202,7 +202,7 @@ pub const IMAP_MUTF7: Alphabet = Alphabet::from_str_unchecked(
///
/// See [BinHex 4.0 Definition](http://files.stairways.com/other/binhex-40-specs-info.txt)
pub const BIN_HEX: Alphabet = Alphabet::from_str_unchecked(
"!\"#$%&'()*+,-0123456789@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdehijklmpqr",
"!\"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr",
);
#[cfg(test)]

View File

@ -109,6 +109,7 @@ pub trait Engine: Send + Sync {
/// engine::GeneralPurpose::new(&alphabet::URL_SAFE, general_purpose::NO_PAD);
///
/// let b64_url = CUSTOM_ENGINE.encode(b"hello internet~");
/// ```
#[cfg(any(feature = "alloc", test))]
#[inline]
fn encode<T: AsRef<[u8]>>(&self, input: T) -> String {

View File

@ -77,7 +77,7 @@ fn trailing_junk() {
break;
}
Ok(0) => break,
Ok(_) => (),
Ok(_len) => (),
}
}

View File

@ -1 +1 @@
{"files":{"CHANGELOG.md":"326deeb7eb3ae12b03b09223076fce85ab7776cf84efa2210421dc43c5aa7d26","CODE_OF_CONDUCT.md":"42634d0f6d922f49857175af991802822f7f920487aefa2ee250a50d12251a66","CONTRIBUTING.md":"6c9f96eacb20af877ae2d16f024904f3038b93448a8488e9dbcac0df7f6439a5","Cargo.lock":"8bc439f84c6c8f3ead3e55a838cc2240b67286450affaefb2d7bf9909892a084","Cargo.toml":"7e4762a4f26f8e948016e518a034a44324b308355f976420b87c898d59214fad","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"1319a2e116738d00c39fa9044ebb20921f270535e97d7648c5414d3fe90af7f0","SECURITY.md":"68704c8128fa2e776ed7cbda741fbf61ad52f998a96350ee7ee4dbf64c6573bc","benches/parse.rs":"f1390d62322c6880d65bd931e183d49b313f287879a6bfaa36b1cb1921090b51","examples/custom_bits_type.rs":"e53b32051adc5d97860e0b48c8f3a301a041d73b4939c0d7caa5f0cfcc0b9739","examples/custom_derive.rs":"29dd7b845345a103ca31e91b579aeb01fb74935b8223c29184eb42223edadb65","examples/fmt.rs":"87ba37a1fb8528570c74ea26d8e8948e1179c3d867b928bea1080880258e0a99","examples/macro_free.rs":"69e7f284b53b5214d51228a686e87f127b52a3b74711e45537ebfa5583a180e5","examples/serde.rs":"08b21b35d5c10fdca132fe0f36c8067bb44f559e96617a9257ab6316a20cbc75","spec.md":"fcdd939df30c59b0643be09027df664b71cbea9b9989185441482c5576160fed","src/example_generated.rs":"d018caf059f6ffc4c2403b771a6d76679fa5af03c329a91bd9252957df695e7f","src/external.rs":"734d3f470e6a669297d2df421ce3976fe613d8aa9c071d5ce6fe3ca890e5b815","src/external/arbitrary.rs":"fa8c9187028b9bc54856977b0914676f62101010e7a9450abd577fd78c89552f","src/external/bytemuck.rs":"3afcef382122867040fddd5e4153d633d1ed5596fe5d7dfac66a8e61c2513df5","src/external/serde.rs":"4a09db12534a20fe554a08dc5f1c8124b379292d41fa75628abcd2ca21587573","src/internal.rs":"645b13af0c7302258df61239073a4b8203d09f27b6c17f8a6f1f8c3e427f5334","src/iter.rs":"dbaa6437c1c044f689185ce3fafe43df8796bed19bbdd2c20334a52de5eeee73","src/lib.rs":"054e839f46b021976c74c3edb6c1fca49f4208dd0d9c9c0b7b95d69285aee69a","src/parser.rs":"52f6352620ce3d5973bc38b42d56a760307294162c9d5668eb774eb92a6ef941","src/public.rs":"d151f7db62fefdb6cd2cad1038a785f02d1ce32eaab4c4cc84376283699182cc","src/tests.rs":"b120c27ff0c67a819527de9d8171f1f4c5d37ba4009c54abeb869c70e6035f14","src/tests/all.rs":"e99a865cd4271a524c2fe95503e96d851b35990570aed6fb2e9dac7a14da31b6","src/tests/bits.rs":"3840c34b2ea5d1802404b9ce5bcc1d3fa6ccd8dfba2e29e6d07c605f817d90df","src/tests/complement.rs":"d0e6d4c3daf49e0a7438c9f1c1ac91fad1b37f258c03593f6cd6a695ee626f5e","src/tests/contains.rs":"58bb3cb8c86550e775d11134da1d4aca85c83f943ea454e3a5f222772c674a24","src/tests/difference.rs":"d0d2b96bb52658b8ac019210da74ca75a53e76622f668855142ea6e97c28cb0e","src/tests/empty.rs":"817d6e93ced7cb7576ff0e334aa1a44703f3f96871ff2c6bdcb8f207e6551f67","src/tests/eq.rs":"b816767680a029e9c163e37af074dd4e604c4a3e4936f829f0ca3774fd5f0e37","src/tests/extend.rs":"5fabb9fd0254c64da019149c24063fceff72da3eb4ad73b57c1cc4c04b008364","src/tests/flags.rs":"2f48d3a25db1cf66fe98c9959abc70875deb9f7b38b2c278dc70c46e0d4ec277","src/tests/fmt.rs":"a2d4148491f3202f030f63633eee941b741e3be29a68cf376f008dbe5cb11e5c","src/tests/from_bits.rs":"d94c65b88bf89961d0cfc1b3152a7f1acc285bae160a1628438effda11b8e2c1","src/tests/from_bits_retain.rs":"980591dfaf91e940f42d9a1ce890f237514dd59d458fc264abcf9ceabbc40677","src/tests/from_bits_truncate.rs":"d3406b5e107ebb6449b98a59eee6cc5d84f947d4aaee1ee7e80dc7202de179f0","src/tests/from_name.rs":"f4a055d1f3c86decef70ef8f3020cef5c4e229718c20b3d59d5a3abc3a8b1298","src/tests/insert.rs":"3fab5da800a6fc0654dfb5f859f95da65a507eb9fda8695083c2712266dff0b9","src/tests/intersection.rs":"baf1454c9e4eba552264870a556ee0032d9f2bb8cac361833d571235e0b52221","src/tests/intersects.rs":"c55e36179fd8bc636f04ea9bbce346dcaafe57915d13f1df28c5b83117dbd08e","src/tests/is_all.rs":"b2f11faa7c954bd85c8fb39999e0c37d983cf7895152bc13c7ddde106aa33b6d","src/tests/is_empty.rs":"11f21323cdca7ff92dd89e09de667dba69e8dce88e2d3e27ea68ace91d15d070","src/tests/iter.rs":"4ba121932b527e787b82745405c7c65c1084c242e2dda3290d475ec160d265e4","src/tests/parser.rs":"237c0b34f7e52c60b18111cde8c72d554565aa9899edece360ae2677f98675c9","src/tests/remove.rs":"6e75f8508d2dc1a2cba89ef691f4387a665a4fd13853bb1dd0fd80c783b89947","src/tests/symmetric_difference.rs":"0a89f084f9de1dd5b1932fe72c3b10a3c93cbaa16832b3a31b6a85e3bbd3ba6e","src/tests/union.rs":"88f398ee4600bb1e59bf6d02d1f6ff33f5f853eab5a6c700bd8a683c6ee4651a","src/traits.rs":"0a8764c3e2378043e2724cf1bfc514d4ff1985026db33509f6451a7897e2675d"},"package":"ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"}
{"files":{"CHANGELOG.md":"c98723b209ac4c66625e034b113a55a43a5c1c9e49c0e3b86123d0cd62bae573","CODE_OF_CONDUCT.md":"42634d0f6d922f49857175af991802822f7f920487aefa2ee250a50d12251a66","CONTRIBUTING.md":"6c9f96eacb20af877ae2d16f024904f3038b93448a8488e9dbcac0df7f6439a5","Cargo.lock":"d3e3bce47b94298f2de893a7d91035f2b73a887905a7ffd4ddb668efdd0aee20","Cargo.toml":"92e110c36340bda13f3b329a2aa24aede8bdcb7fa035806926f7ce438dde87f2","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"e9b1329fee85868f1aa674d0505cd95b86a259e2a1762347e5af4a5abedd61d4","SECURITY.md":"68704c8128fa2e776ed7cbda741fbf61ad52f998a96350ee7ee4dbf64c6573bc","benches/parse.rs":"f1390d62322c6880d65bd931e183d49b313f287879a6bfaa36b1cb1921090b51","examples/custom_bits_type.rs":"e53b32051adc5d97860e0b48c8f3a301a041d73b4939c0d7caa5f0cfcc0b9739","examples/custom_derive.rs":"a404e8f606efdd1b43e0c365e4142ccc3dc3ba230127ddeea89cd8784bb55a1e","examples/fmt.rs":"87ba37a1fb8528570c74ea26d8e8948e1179c3d867b928bea1080880258e0a99","examples/macro_free.rs":"69e7f284b53b5214d51228a686e87f127b52a3b74711e45537ebfa5583a180e5","examples/serde.rs":"08b21b35d5c10fdca132fe0f36c8067bb44f559e96617a9257ab6316a20cbc75","spec.md":"fcdd939df30c59b0643be09027df664b71cbea9b9989185441482c5576160fed","src/example_generated.rs":"d018caf059f6ffc4c2403b771a6d76679fa5af03c329a91bd9252957df695e7f","src/external.rs":"734d3f470e6a669297d2df421ce3976fe613d8aa9c071d5ce6fe3ca890e5b815","src/external/arbitrary.rs":"fa8c9187028b9bc54856977b0914676f62101010e7a9450abd577fd78c89552f","src/external/bytemuck.rs":"3afcef382122867040fddd5e4153d633d1ed5596fe5d7dfac66a8e61c2513df5","src/external/serde.rs":"4a09db12534a20fe554a08dc5f1c8124b379292d41fa75628abcd2ca21587573","src/internal.rs":"645b13af0c7302258df61239073a4b8203d09f27b6c17f8a6f1f8c3e427f5334","src/iter.rs":"dbaa6437c1c044f689185ce3fafe43df8796bed19bbdd2c20334a52de5eeee73","src/lib.rs":"1feb0eea02f88491c99c7962b0ce6e66bdedea0ab0cac375d4c9c2d879248dc7","src/parser.rs":"4e788b29f5d0542c409a8b43c703bcb4a6c2a57c181cadd17f565f0abb39681e","src/public.rs":"78ba06e1a5830b36960adf9bd79aaf47d783b9b8a0f1fa33b0d7a340c15fd1d1","src/tests.rs":"b120c27ff0c67a819527de9d8171f1f4c5d37ba4009c54abeb869c70e6035f14","src/tests/all.rs":"e99a865cd4271a524c2fe95503e96d851b35990570aed6fb2e9dac7a14da31b6","src/tests/bits.rs":"3840c34b2ea5d1802404b9ce5bcc1d3fa6ccd8dfba2e29e6d07c605f817d90df","src/tests/complement.rs":"d0e6d4c3daf49e0a7438c9f1c1ac91fad1b37f258c03593f6cd6a695ee626f5e","src/tests/contains.rs":"58bb3cb8c86550e775d11134da1d4aca85c83f943ea454e3a5f222772c674a24","src/tests/difference.rs":"d0d2b96bb52658b8ac019210da74ca75a53e76622f668855142ea6e97c28cb0e","src/tests/empty.rs":"817d6e93ced7cb7576ff0e334aa1a44703f3f96871ff2c6bdcb8f207e6551f67","src/tests/eq.rs":"b816767680a029e9c163e37af074dd4e604c4a3e4936f829f0ca3774fd5f0e37","src/tests/extend.rs":"5fabb9fd0254c64da019149c24063fceff72da3eb4ad73b57c1cc4c04b008364","src/tests/flags.rs":"2f48d3a25db1cf66fe98c9959abc70875deb9f7b38b2c278dc70c46e0d4ec277","src/tests/fmt.rs":"a2d4148491f3202f030f63633eee941b741e3be29a68cf376f008dbe5cb11e5c","src/tests/from_bits.rs":"d94c65b88bf89961d0cfc1b3152a7f1acc285bae160a1628438effda11b8e2c1","src/tests/from_bits_retain.rs":"980591dfaf91e940f42d9a1ce890f237514dd59d458fc264abcf9ceabbc40677","src/tests/from_bits_truncate.rs":"d3406b5e107ebb6449b98a59eee6cc5d84f947d4aaee1ee7e80dc7202de179f0","src/tests/from_name.rs":"f4a055d1f3c86decef70ef8f3020cef5c4e229718c20b3d59d5a3abc3a8b1298","src/tests/insert.rs":"3fab5da800a6fc0654dfb5f859f95da65a507eb9fda8695083c2712266dff0b9","src/tests/intersection.rs":"baf1454c9e4eba552264870a556ee0032d9f2bb8cac361833d571235e0b52221","src/tests/intersects.rs":"c55e36179fd8bc636f04ea9bbce346dcaafe57915d13f1df28c5b83117dbd08e","src/tests/is_all.rs":"b2f11faa7c954bd85c8fb39999e0c37d983cf7895152bc13c7ddde106aa33b6d","src/tests/is_empty.rs":"11f21323cdca7ff92dd89e09de667dba69e8dce88e2d3e27ea68ace91d15d070","src/tests/iter.rs":"4ba121932b527e787b82745405c7c65c1084c242e2dda3290d475ec160d265e4","src/tests/parser.rs":"fa2fb8dedcf16601af609a5e21d9c5840c7f96a1e3a587f7f2ea3dc8387f7628","src/tests/remove.rs":"6e75f8508d2dc1a2cba89ef691f4387a665a4fd13853bb1dd0fd80c783b89947","src/tests/symmetric_difference.rs":"0a89f084f9de1dd5b1932fe72c3b10a3c93cbaa16832b3a31b6a85e3bbd3ba6e","src/tests/union.rs":"88f398ee4600bb1e59bf6d02d1f6ff33f5f853eab5a6c700bd8a683c6ee4651a","src/traits.rs":"b79d008daec546136fae4497966fc85a33663d86ea2d9213fd23b412d4d77b66"},"package":"b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"}

View File

@ -1,3 +1,33 @@
# 2.6.0
## What's Changed
* Sync CHANGELOG.md with github release notes by @dextero in https://github.com/bitflags/bitflags/pull/402
* Update error messages and zerocopy by @KodrAus in https://github.com/bitflags/bitflags/pull/403
* Bump minimum declared versions of dependencies by @dextero in https://github.com/bitflags/bitflags/pull/404
* chore(deps): bump serde_derive and bytemuck versions by @joshka in https://github.com/bitflags/bitflags/pull/405
* add OSFF Scorecard workflow by @KodrAus in https://github.com/bitflags/bitflags/pull/396
* Update stderr messages by @KodrAus in https://github.com/bitflags/bitflags/pull/408
* Fix typo by @waywardmonkeys in https://github.com/bitflags/bitflags/pull/410
* Allow specifying outer attributes in impl mode by @KodrAus in https://github.com/bitflags/bitflags/pull/411
## New Contributors
* @dextero made their first contribution in https://github.com/bitflags/bitflags/pull/402
* @joshka made their first contribution in https://github.com/bitflags/bitflags/pull/405
* @waywardmonkeys made their first contribution in https://github.com/bitflags/bitflags/pull/410
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.5.0...2.6.0
# 2.5.0
## What's Changed
* Derive `Debug` for `Flag<B>` by @tgross35 in https://github.com/bitflags/bitflags/pull/398
* Support truncating or strict-named variants of parsing and formatting by @KodrAus in https://github.com/bitflags/bitflags/pull/400
## New Contributors
* @tgross35 made their first contribution in https://github.com/bitflags/bitflags/pull/398
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.4.2...2.5.0
# 2.4.2
## What's Changed
@ -80,7 +110,20 @@ to a valid flag.
# 2.3.0
## Major changes
### `BitFlags` trait deprecated in favor of `Flags` trait
This release introduces the `Flags` trait and deprecates the `BitFlags` trait. These two traits are semver compatible so if you have public API code depending on `BitFlags` you can move to `Flags` without breaking end-users. This is possible because the `BitFlags` trait was never publicly implementable, so it now carries `Flags` as a supertrait. All implementations of `Flags` additionally implement `BitFlags`.
The `Flags` trait is a publicly implementable version of the old `BitFlags` trait. The original `BitFlags` trait carried some macro baggage that made it difficult to implement, so a new `Flags` trait has been introduced as the _One True Trait_ for interacting with flags types generically. See the the `macro_free` and `custom_derive` examples for more details.
### `Bits` trait publicly exposed
The `Bits` trait for the underlying storage of flags values is also now publicly implementable. This lets you define your own exotic backing storage for flags. See the `custom_bits_type` example for more details.
## What's Changed
* Use explicit hashes for actions steps by @KodrAus in https://github.com/bitflags/bitflags/pull/350
* Support ejecting flags types from the bitflags macro by @KodrAus in https://github.com/bitflags/bitflags/pull/351
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.2.1...2.3.0
@ -139,6 +182,59 @@ to a valid flag.
# 2.0.0
## Major changes
This release includes some major changes over `1.x`. If you use `bitflags!` types in your public API then upgrading this library may cause breakage in your downstream users.
### ⚠️ Serialization
You'll need to add the `serde` Cargo feature in order to `#[derive(Serialize, Deserialize)]` on your generated flags types:
```rust
bitflags! {
#[derive(Serialize, Deserialize)]
#[serde(transparent)]
pub struct Flags: T {
..
}
}
```
where `T` is the underlying bits type you're using, such as `u32`.
The default serialization format with `serde` **has changed** if you `#[derive(Serialize, Deserialize)]` on your generated flags types. It will now use a formatted string for human-readable formats and the underlying bits type for compact formats.
To keep the old format, see the https://github.com/KodrAus/bitflags-serde-legacy library.
### ⚠️ Traits
Generated flags types now derive fewer traits. If you need to maintain backwards compatibility, you can derive the following yourself:
```rust
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
```
### ⚠️ Methods
The unsafe `from_bits_unchecked` method is now a safe `from_bits_retain` method.
You can add the following method to your generated types to keep them compatible:
```rust
#[deprecated = "use the safe `from_bits_retain` method instead"]
pub unsafe fn from_bits_unchecked(bits: T) -> Self {
Self::from_bits_retain(bits)
}
```
where `T` is the underlying bits type you're using, such as `u32`.
### ⚠️ `.bits` field
You can now use the `.bits()` method instead of the old `.bits`.
The representation of generated flags types has changed from a struct with the single field `bits` to a newtype.
## What's Changed
* Fix a typo and call out MSRV bump by @KodrAus in https://github.com/bitflags/bitflags/pull/259
* BitFlags trait by @arturoc in https://github.com/bitflags/bitflags/pull/220

253
vendor/bitflags/Cargo.lock generated vendored
View File

@ -11,18 +11,9 @@ dependencies = [
"derive_arbitrary",
]
[[package]]
name = "basic-toml"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2db21524cad41c5591204d22d75e1970a2d1f71060214ca931dc7d5afe2c14e5"
dependencies = [
"serde",
]
[[package]]
name = "bitflags"
version = "2.4.2"
version = "2.6.0"
dependencies = [
"arbitrary",
"bytemuck",
@ -39,18 +30,18 @@ dependencies = [
[[package]]
name = "bytemuck"
version = "1.14.0"
version = "1.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6"
checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e"
dependencies = [
"bytemuck_derive",
]
[[package]]
name = "bytemuck_derive"
version = "1.5.0"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1"
checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b"
dependencies = [
"proc-macro2",
"quote",
@ -65,9 +56,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "compiler_builtins"
version = "0.1.105"
version = "0.1.112"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3686cc48897ce1950aa70fd595bd2dc9f767a3c4cca4cd17b2cb52a2d37e6eb4"
checksum = "b15acab2bb4fe4dad1f1e31f3d9e714f50ef561a0f87dd8a9da004f14d455e1a"
[[package]]
name = "derive_arbitrary"
@ -80,6 +71,12 @@ dependencies = [
"syn",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "glob"
version = "0.3.1"
@ -87,31 +84,47 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "itoa"
version = "1.0.10"
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "once_cell"
version = "1.19.0"
name = "indexmap"
version = "2.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "itoa"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "proc-macro2"
version = "1.0.76"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
]
@ -124,30 +137,30 @@ checksum = "1956f5517128a2b6f23ab2dadf1a976f4f5b27962e7724c2bf3d45e539ec098c"
[[package]]
name = "rustversion"
version = "1.0.14"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
[[package]]
name = "ryu"
version = "1.0.16"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "serde"
version = "1.0.195"
version = "1.0.203"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02"
checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.195"
version = "1.0.203"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c"
checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
dependencies = [
"proc-macro2",
"quote",
@ -156,15 +169,24 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.111"
version = "1.0.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4"
checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_spanned"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0"
dependencies = [
"serde",
]
[[package]]
name = "serde_test"
version = "1.0.176"
@ -176,9 +198,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.48"
version = "2.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9"
dependencies = [
"proc-macro2",
"quote",
@ -195,18 +217,51 @@ dependencies = [
]
[[package]]
name = "trybuild"
version = "1.0.89"
name = "toml"
version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a9d3ba662913483d6722303f619e75ea10b7855b0f8e0d72799cf8621bb488f"
checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]]
name = "trybuild"
version = "1.0.96"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33a5f13f11071020bb12de7a16b925d2d58636175c20c11dc5f96cb64bb6c9b3"
dependencies = [
"basic-toml",
"glob",
"once_cell",
"serde",
"serde_derive",
"serde_json",
"termcolor",
"toml",
]
[[package]]
@ -215,42 +270,102 @@ version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.6"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
dependencies = [
"winapi",
"windows-sys",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]]
name = "windows_i686_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
[[package]]
name = "windows_i686_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
[[package]]
name = "winnow"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1"
dependencies = [
"memchr",
]
[[package]]
name = "zerocopy"
version = "0.6.6"
version = "0.7.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854e949ac82d619ee9a14c66a1b674ac730422372ccb759ce0c39cabcf2bf8e6"
checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087"
dependencies = [
"byteorder",
"zerocopy-derive",
@ -258,9 +373,9 @@ dependencies = [
[[package]]
name = "zerocopy-derive"
version = "0.6.6"
version = "0.7.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "125139de3f6b9d625c39e2efdd73d41bdac468ccd556556440e322be0e1bbd91"
checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b"
dependencies = [
"proc-macro2",
"quote",

Some files were not shown because too many files have changed in this diff Show More