From 4547b622d8d29df964fa2914213088b148c498fc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:32 +0200 Subject: Merging upstream version 1.67.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/zerofrom/.cargo-checksum.json | 1 + vendor/zerofrom/Cargo.toml | 51 ++++++++++++ vendor/zerofrom/LICENSE | 51 ++++++++++++ vendor/zerofrom/README.md | 9 +++ vendor/zerofrom/src/lib.rs | 36 +++++++++ vendor/zerofrom/src/macro_impls.rs | 145 +++++++++++++++++++++++++++++++++++ vendor/zerofrom/src/zero_from.rs | 128 +++++++++++++++++++++++++++++++ 7 files changed, 421 insertions(+) create mode 100644 vendor/zerofrom/.cargo-checksum.json create mode 100644 vendor/zerofrom/Cargo.toml create mode 100644 vendor/zerofrom/LICENSE create mode 100644 vendor/zerofrom/README.md create mode 100644 vendor/zerofrom/src/lib.rs create mode 100644 vendor/zerofrom/src/macro_impls.rs create mode 100644 vendor/zerofrom/src/zero_from.rs (limited to 'vendor/zerofrom') diff --git a/vendor/zerofrom/.cargo-checksum.json b/vendor/zerofrom/.cargo-checksum.json new file mode 100644 index 000000000..25b4ab788 --- /dev/null +++ b/vendor/zerofrom/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"e4099dab626c3268392ec01de6bdcf7f1b904aa2206aa9d24ea09060db8c0641","LICENSE":"4ad7541d66a407234e2c84902124cef325c29f3e966353efdb800bedb8b8da21","README.md":"dc0e4a45a140001c02818b1f63f9253d5e84c758e46b88f206cacbc5d0401db9","src/lib.rs":"59afe6e1aa74bd1fdab7b1cafa8b5bd1ede141b5c9018d55b76ed395c2f476e3","src/macro_impls.rs":"6b4b69bdc6b94f2abb64da0c2520d3ff74aff7d14e8b4de9e8022d7ddc951f38","src/zero_from.rs":"d589da84905ca5016e91b47672ac8710f035e4da16160d17328fe520f9a6fdce"},"package":"79e9355fccf72b04b7deaa99ce7a0f6630530acf34045391b74460fcd714de54"} \ No newline at end of file diff --git a/vendor/zerofrom/Cargo.toml b/vendor/zerofrom/Cargo.toml new file mode 100644 index 000000000..77d60c093 --- /dev/null +++ b/vendor/zerofrom/Cargo.toml @@ -0,0 +1,51 @@ +# 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 = "2018" +name = "zerofrom" +version = "0.1.1" +authors = ["Manish Goregaokar "] +include = [ + "src/**/*", + "examples/**/*", + "benches/**/*", + "Cargo.toml", + "LICENSE", + "README.md", +] +description = "ZeroFrom trait for constructing" +keywords = [ + "zerocopy", + "serialization", + "lifetime", + "borrow", +] +categories = [ + "data-structures", + "caching", + "no-std", +] +license = "Unicode-DFS-2016" +repository = "https://github.com/unicode-org/icu4x" +resolver = "2" + +[package.metadata.docs.rs] +all-features = true + +[dependencies.zerofrom-derive] +version = "0.1.0" +optional = true + +[features] +alloc = [] +default = ["alloc"] +derive = ["zerofrom-derive"] diff --git a/vendor/zerofrom/LICENSE b/vendor/zerofrom/LICENSE new file mode 100644 index 000000000..9858d01ab --- /dev/null +++ b/vendor/zerofrom/LICENSE @@ -0,0 +1,51 @@ +UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE + +See Terms of Use +for definitions of Unicode Inc.’s Data Files and Software. + +NOTICE TO USER: Carefully read the following legal agreement. +BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S +DATA FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"), +YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE +TERMS AND CONDITIONS OF THIS AGREEMENT. +IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE +THE DATA FILES OR SOFTWARE. + +COPYRIGHT AND PERMISSION NOTICE + +Copyright © 1991-2022 Unicode, Inc. All rights reserved. +Distributed under the Terms of Use in https://www.unicode.org/copyright.html. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Unicode data files and any associated documentation +(the "Data Files") or Unicode software and any associated documentation +(the "Software") to deal in the Data Files or Software +without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, and/or sell copies of +the Data Files or Software, and to permit persons to whom the Data Files +or Software are furnished to do so, provided that either +(a) this copyright and permission notice appear with all copies +of the Data Files or Software, or +(b) this copyright and permission notice appear in associated +Documentation. + +THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT OF THIRD PARTY RIGHTS. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS +NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 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 THE DATA FILES OR SOFTWARE. + +Except as contained in this notice, the name of a copyright holder +shall not be used in advertising or otherwise to promote the sale, +use or other dealings in these Data Files or Software without prior +written authorization of the copyright holder. + +— + +Portions of ICU4X may have been adapted from ICU4C and/or ICU4J. +ICU 1.8.1 to ICU 57.1 © 1995-2016 International Business Machines Corporation and others. diff --git a/vendor/zerofrom/README.md b/vendor/zerofrom/README.md new file mode 100644 index 000000000..d268a347e --- /dev/null +++ b/vendor/zerofrom/README.md @@ -0,0 +1,9 @@ +# zerofrom [![crates.io](https://img.shields.io/crates/v/zerofrom)](https://crates.io/crates/zerofrom) + +This crate provides [`ZeroFrom`], a trait for converting types in a zero-copy way. + +See the documentation of [`ZeroFrom`] for more details. + +## More Information + +For more information on development, authorship, contributing etc. please visit [`ICU4X home page`](https://github.com/unicode-org/icu4x). diff --git a/vendor/zerofrom/src/lib.rs b/vendor/zerofrom/src/lib.rs new file mode 100644 index 000000000..7b47613fd --- /dev/null +++ b/vendor/zerofrom/src/lib.rs @@ -0,0 +1,36 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +//! This crate provides [`ZeroFrom`], a trait for converting types in a zero-copy way. +//! +//! See the documentation of [`ZeroFrom`] for more details. + +// https://github.com/unicode-org/icu4x/blob/main/docs/process/boilerplate.md#library-annotations +#![cfg_attr(not(test), no_std)] +#![cfg_attr( + not(test), + deny( + clippy::indexing_slicing, + clippy::unwrap_used, + clippy::expect_used, + clippy::panic, + clippy::exhaustive_structs, + clippy::exhaustive_enums, + missing_debug_implementations, + ) +)] +// The lifetimes here are important for safety and explicitly writing +// them out is good even when redundant +#![allow(clippy::needless_lifetimes)] + +#[cfg(feature = "alloc")] +extern crate alloc; + +mod macro_impls; +mod zero_from; + +#[cfg(feature = "derive")] +pub use zerofrom_derive::ZeroFrom; + +pub use crate::zero_from::ZeroFrom; diff --git a/vendor/zerofrom/src/macro_impls.rs b/vendor/zerofrom/src/macro_impls.rs new file mode 100644 index 000000000..3bef457e1 --- /dev/null +++ b/vendor/zerofrom/src/macro_impls.rs @@ -0,0 +1,145 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +// In this case consistency between impls is more important +// than using pointer casts +#![allow(clippy::transmute_ptr_to_ptr)] + +use crate::ZeroFrom; + +macro_rules! impl_copy_type { + ($ty:ident) => { + impl<'a> ZeroFrom<'a, $ty> for $ty { + #[inline] + fn zero_from(this: &'a Self) -> Self { + // Essentially only works when the struct is fully Copy + *this + } + } + }; +} + +impl_copy_type!(u8); +impl_copy_type!(u16); +impl_copy_type!(u32); +impl_copy_type!(u64); +impl_copy_type!(u128); +impl_copy_type!(usize); +impl_copy_type!(i8); +impl_copy_type!(i16); +impl_copy_type!(i32); +impl_copy_type!(i64); +impl_copy_type!(i128); +impl_copy_type!(isize); +impl_copy_type!(char); +impl_copy_type!(bool); + +// This can be cleaned up once `[T; N]`::each_ref() is stabilized +// https://github.com/rust-lang/rust/issues/76118 +macro_rules! array_zf_impl { + ($n:expr; $($i:expr),+) => { + impl<'a, C, T: ZeroFrom<'a, C>> ZeroFrom<'a, [C; $n]> for [T; $n] { + fn zero_from(this: &'a [C; $n]) -> Self { + [ + $( + >::zero_from(&this[$i]) + ),+ + + ] + } + } + } +} + +array_zf_impl!(1; 0); +array_zf_impl!(2; 0, 1); +array_zf_impl!(3; 0, 1, 2); +array_zf_impl!(4; 0, 1, 2, 3); +array_zf_impl!(5; 0, 1, 2, 3, 4); +array_zf_impl!(6; 0, 1, 2, 3, 4, 5); +array_zf_impl!(7; 0, 1, 2, 3, 4, 5, 6); +array_zf_impl!(8; 0, 1, 2, 3, 4, 5, 6, 7); +array_zf_impl!(9; 0, 1, 2, 3, 4, 5, 6, 7, 8); +array_zf_impl!(10; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); +array_zf_impl!(11; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); +array_zf_impl!(12; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); +array_zf_impl!(13; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); +array_zf_impl!(14; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13); +array_zf_impl!(15; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14); +array_zf_impl!(16; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + +macro_rules! tuple_zf_impl { + ($(($c:ident, $t:ident, $i:tt)),+) => { + impl<'zf, $($c, $t: ZeroFrom<'zf, $c>),+> ZeroFrom<'zf, ($($c),+)> + for ($($t),+) + { + fn zero_from(other: &'zf ($($c),+)) -> Self { + ( + $(<$t as ZeroFrom<$c>>::zero_from(&other.$i)),+ + ) + } + } + }; +} + +tuple_zf_impl!((C1, T1, 0), (C2, T2, 1)); +tuple_zf_impl!((C1, T1, 0), (C2, T2, 1), (C3, T3, 2)); +tuple_zf_impl!((C1, T1, 0), (C2, T2, 1), (C3, T3, 2), (C4, T4, 3)); +tuple_zf_impl!( + (C1, T1, 0), + (C2, T2, 1), + (C3, T3, 2), + (C4, T4, 3), + (C5, T5, 4) +); +tuple_zf_impl!( + (C1, T1, 0), + (C2, T2, 1), + (C3, T3, 2), + (C4, T4, 3), + (C5, T5, 4), + (C6, T6, 5) +); +tuple_zf_impl!( + (C1, T1, 0), + (C2, T2, 1), + (C3, T3, 2), + (C4, T4, 3), + (C5, T5, 4), + (C6, T6, 5), + (C7, T7, 6) +); +tuple_zf_impl!( + (C1, T1, 0), + (C2, T2, 1), + (C3, T3, 2), + (C4, T4, 3), + (C5, T5, 4), + (C6, T6, 5), + (C7, T7, 6), + (C8, T8, 7) +); +tuple_zf_impl!( + (C1, T1, 0), + (C2, T2, 1), + (C3, T3, 2), + (C4, T4, 3), + (C5, T5, 4), + (C6, T6, 5), + (C7, T7, 6), + (C8, T8, 7), + (C9, T9, 8) +); +tuple_zf_impl!( + (C1, T1, 0), + (C2, T2, 1), + (C3, T3, 2), + (C4, T4, 3), + (C5, T5, 4), + (C6, T6, 5), + (C7, T7, 6), + (C8, T8, 7), + (C9, T9, 8), + (C10, T10, 9) +); diff --git a/vendor/zerofrom/src/zero_from.rs b/vendor/zerofrom/src/zero_from.rs new file mode 100644 index 000000000..5b89ea5fb --- /dev/null +++ b/vendor/zerofrom/src/zero_from.rs @@ -0,0 +1,128 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +#[cfg(feature = "alloc")] +use alloc::borrow::{Cow, ToOwned}; +#[cfg(feature = "alloc")] +use alloc::string::String; + +/// Trait for types that can be created from a reference to a different type `C` with no allocations, +/// i.e. a zero-copy (zero-alloc) version of "From" +/// +/// A type can be the `ZeroFrom` target of multiple other types. +/// +/// The intention is for `ZeroFrom` to produce a struct from a other with as little work as +/// possible. Although it is technically possible to implement `ZeroFrom` without being +/// zero-copy (using heap allocations), doing so defeats the purpose of `ZeroFrom`. +/// +/// For example, `impl ZeroFrom for Cow` should return a `Cow::Borrowed` pointing at +/// data in the other type `C`, even if the other type is itself fully owned. +/// +/// One can use the [`#[derive(ZeroFrom)]`](zerofrom_derive::ZeroFrom) custom derive to automatically +/// implement this trait. +/// +/// # Examples +/// +/// Implementing `ZeroFrom` on a custom data struct: +/// +/// ``` +/// use std::borrow::Cow; +/// use zerofrom::ZeroFrom; +/// +/// struct MyStruct<'data> { +/// message: Cow<'data, str>, +/// } +/// +/// // Reference from a borrowed version of self +/// impl<'zf> ZeroFrom<'zf, MyStruct<'_>> for MyStruct<'zf> { +/// fn zero_from(other: &'zf MyStruct<'_>) -> Self { +/// MyStruct { +/// message: Cow::Borrowed(&other.message), +/// } +/// } +/// } +/// +/// // Reference from a string slice directly +/// impl<'zf> ZeroFrom<'zf, str> for MyStruct<'zf> { +/// fn zero_from(other: &'zf str) -> Self { +/// MyStruct { +/// message: Cow::Borrowed(other), +/// } +/// } +/// } +/// ``` +pub trait ZeroFrom<'zf, C: ?Sized>: 'zf { + /// Clone the other `C` into a struct that may retain references into `C`. + fn zero_from(other: &'zf C) -> Self; +} + +// Note: The following could be blanket implementations, but that would require constraining the +// blanket `T` on `T: 'static`, which may not be desirable for all downstream users who may wish +// to customize their `ZeroFrom` impl. The blanket implementation may be safe once Rust has +// specialization. + +#[cfg(feature = "alloc")] +impl<'zf> ZeroFrom<'zf, str> for Cow<'zf, str> { + #[inline] + fn zero_from(other: &'zf str) -> Self { + Cow::Borrowed(other) + } +} + +#[cfg(feature = "alloc")] +impl<'zf> ZeroFrom<'zf, String> for Cow<'zf, str> { + #[inline] + fn zero_from(other: &'zf String) -> Self { + Cow::Borrowed(other) + } +} + +impl<'zf> ZeroFrom<'zf, str> for &'zf str { + #[inline] + fn zero_from(other: &'zf str) -> Self { + other + } +} + +#[cfg(feature = "alloc")] +impl<'zf> ZeroFrom<'zf, String> for &'zf str { + #[inline] + fn zero_from(other: &'zf String) -> Self { + other + } +} + +impl<'zf, C, T: ZeroFrom<'zf, C>> ZeroFrom<'zf, Option> for Option { + fn zero_from(other: &'zf Option) -> Self { + other.as_ref().map(|c| >::zero_from(c)) + } +} + +// These duplicate the functionality from above and aren't quite necessary due +// to deref coercions, however for the custom derive to work, there always needs +// to be `impl ZeroFrom for T`, otherwise it may fail to perform the necessary +// type inference. Deref coercions do not typically work when sufficient generics +// or inference are involved, and the proc macro does not necessarily have +// enough type information to figure this out on its own. +#[cfg(feature = "alloc")] +impl<'zf, B: ToOwned + ?Sized> ZeroFrom<'zf, Cow<'_, B>> for Cow<'zf, B> { + #[inline] + fn zero_from(other: &'zf Cow<'_, B>) -> Self { + Cow::Borrowed(other) + } +} + +impl<'zf> ZeroFrom<'zf, &'_ str> for &'zf str { + #[inline] + fn zero_from(other: &'zf &'_ str) -> &'zf str { + other + } +} + +impl<'zf, T> ZeroFrom<'zf, [T]> for &'zf [T] { + #[inline] + fn zero_from(other: &'zf [T]) -> &'zf [T] { + other + } +} -- cgit v1.2.3