Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

64
vendor/either/src/into_either.rs vendored Normal file
View File

@@ -0,0 +1,64 @@
//! The trait [`IntoEither`] provides methods for converting a type `Self`, whose
//! size is constant and known at compile-time, into an [`Either`] variant.
use super::{Either, Left, Right};
/// Provides methods for converting a type `Self` into either a [`Left`] or [`Right`]
/// variant of [`Either<Self, Self>`](Either).
///
/// The [`into_either`](IntoEither::into_either) method takes a [`bool`] to determine
/// whether to convert to [`Left`] or [`Right`].
///
/// The [`into_either_with`](IntoEither::into_either_with) method takes a
/// [predicate function](FnOnce) to determine whether to convert to [`Left`] or [`Right`].
pub trait IntoEither: Sized {
/// Converts `self` into a [`Left`] variant of [`Either<Self, Self>`](Either)
/// if `into_left` is `true`.
/// Converts `self` into a [`Right`] variant of [`Either<Self, Self>`](Either)
/// otherwise.
///
/// # Examples
///
/// ```
/// use either::{IntoEither, Left, Right};
///
/// let x = 0;
/// assert_eq!(x.into_either(true), Left(x));
/// assert_eq!(x.into_either(false), Right(x));
/// ```
fn into_either(self, into_left: bool) -> Either<Self, Self> {
if into_left {
Left(self)
} else {
Right(self)
}
}
/// Converts `self` into a [`Left`] variant of [`Either<Self, Self>`](Either)
/// if `into_left(&self)` returns `true`.
/// Converts `self` into a [`Right`] variant of [`Either<Self, Self>`](Either)
/// otherwise.
///
/// # Examples
///
/// ```
/// use either::{IntoEither, Left, Right};
///
/// fn is_even(x: &u8) -> bool {
/// x % 2 == 0
/// }
///
/// let x = 0;
/// assert_eq!(x.into_either_with(is_even), Left(x));
/// assert_eq!(x.into_either_with(|x| !is_even(x)), Right(x));
/// ```
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where
F: FnOnce(&Self) -> bool,
{
let into_left = into_left(&self);
self.into_either(into_left)
}
}
impl<T> IntoEither for T {}

315
vendor/either/src/iterator.rs vendored Normal file
View File

@@ -0,0 +1,315 @@
use super::{for_both, Either, Left, Right};
use core::iter;
macro_rules! wrap_either {
($value:expr => $( $tail:tt )*) => {
match $value {
Left(inner) => inner.map(Left) $($tail)*,
Right(inner) => inner.map(Right) $($tail)*,
}
};
}
/// Iterator that maps left or right iterators to corresponding `Either`-wrapped items.
///
/// This struct is created by the [`Either::factor_into_iter`],
/// [`factor_iter`][Either::factor_iter],
/// and [`factor_iter_mut`][Either::factor_iter_mut] methods.
#[derive(Clone, Debug)]
pub struct IterEither<L, R> {
inner: Either<L, R>,
}
impl<L, R> IterEither<L, R> {
pub(crate) fn new(inner: Either<L, R>) -> Self {
IterEither { inner }
}
}
impl<L, R, A> Extend<A> for Either<L, R>
where
L: Extend<A>,
R: Extend<A>,
{
fn extend<T>(&mut self, iter: T)
where
T: IntoIterator<Item = A>,
{
for_both!(self, inner => inner.extend(iter))
}
}
/// `Either<L, R>` is an iterator if both `L` and `R` are iterators.
impl<L, R> Iterator for Either<L, R>
where
L: Iterator,
R: Iterator<Item = L::Item>,
{
type Item = L::Item;
fn next(&mut self) -> Option<Self::Item> {
for_both!(self, inner => inner.next())
}
fn size_hint(&self) -> (usize, Option<usize>) {
for_both!(self, inner => inner.size_hint())
}
fn fold<Acc, G>(self, init: Acc, f: G) -> Acc
where
G: FnMut(Acc, Self::Item) -> Acc,
{
for_both!(self, inner => inner.fold(init, f))
}
fn for_each<F>(self, f: F)
where
F: FnMut(Self::Item),
{
for_both!(self, inner => inner.for_each(f))
}
fn count(self) -> usize {
for_both!(self, inner => inner.count())
}
fn last(self) -> Option<Self::Item> {
for_both!(self, inner => inner.last())
}
fn nth(&mut self, n: usize) -> Option<Self::Item> {
for_both!(self, inner => inner.nth(n))
}
fn collect<B>(self) -> B
where
B: iter::FromIterator<Self::Item>,
{
for_both!(self, inner => inner.collect())
}
fn partition<B, F>(self, f: F) -> (B, B)
where
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
{
for_both!(self, inner => inner.partition(f))
}
fn all<F>(&mut self, f: F) -> bool
where
F: FnMut(Self::Item) -> bool,
{
for_both!(self, inner => inner.all(f))
}
fn any<F>(&mut self, f: F) -> bool
where
F: FnMut(Self::Item) -> bool,
{
for_both!(self, inner => inner.any(f))
}
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where
P: FnMut(&Self::Item) -> bool,
{
for_both!(self, inner => inner.find(predicate))
}
fn find_map<B, F>(&mut self, f: F) -> Option<B>
where
F: FnMut(Self::Item) -> Option<B>,
{
for_both!(self, inner => inner.find_map(f))
}
fn position<P>(&mut self, predicate: P) -> Option<usize>
where
P: FnMut(Self::Item) -> bool,
{
for_both!(self, inner => inner.position(predicate))
}
}
impl<L, R> DoubleEndedIterator for Either<L, R>
where
L: DoubleEndedIterator,
R: DoubleEndedIterator<Item = L::Item>,
{
fn next_back(&mut self) -> Option<Self::Item> {
for_both!(self, inner => inner.next_back())
}
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
for_both!(self, inner => inner.nth_back(n))
}
fn rfold<Acc, G>(self, init: Acc, f: G) -> Acc
where
G: FnMut(Acc, Self::Item) -> Acc,
{
for_both!(self, inner => inner.rfold(init, f))
}
fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>
where
P: FnMut(&Self::Item) -> bool,
{
for_both!(self, inner => inner.rfind(predicate))
}
}
impl<L, R> ExactSizeIterator for Either<L, R>
where
L: ExactSizeIterator,
R: ExactSizeIterator<Item = L::Item>,
{
fn len(&self) -> usize {
for_both!(self, inner => inner.len())
}
}
impl<L, R> iter::FusedIterator for Either<L, R>
where
L: iter::FusedIterator,
R: iter::FusedIterator<Item = L::Item>,
{
}
impl<L, R> Iterator for IterEither<L, R>
where
L: Iterator,
R: Iterator,
{
type Item = Either<L::Item, R::Item>;
fn next(&mut self) -> Option<Self::Item> {
Some(map_either!(self.inner, ref mut inner => inner.next()?))
}
fn size_hint(&self) -> (usize, Option<usize>) {
for_both!(self.inner, ref inner => inner.size_hint())
}
fn fold<Acc, G>(self, init: Acc, f: G) -> Acc
where
G: FnMut(Acc, Self::Item) -> Acc,
{
wrap_either!(self.inner => .fold(init, f))
}
fn for_each<F>(self, f: F)
where
F: FnMut(Self::Item),
{
wrap_either!(self.inner => .for_each(f))
}
fn count(self) -> usize {
for_both!(self.inner, inner => inner.count())
}
fn last(self) -> Option<Self::Item> {
Some(map_either!(self.inner, inner => inner.last()?))
}
fn nth(&mut self, n: usize) -> Option<Self::Item> {
Some(map_either!(self.inner, ref mut inner => inner.nth(n)?))
}
fn collect<B>(self) -> B
where
B: iter::FromIterator<Self::Item>,
{
wrap_either!(self.inner => .collect())
}
fn partition<B, F>(self, f: F) -> (B, B)
where
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
{
wrap_either!(self.inner => .partition(f))
}
fn all<F>(&mut self, f: F) -> bool
where
F: FnMut(Self::Item) -> bool,
{
wrap_either!(&mut self.inner => .all(f))
}
fn any<F>(&mut self, f: F) -> bool
where
F: FnMut(Self::Item) -> bool,
{
wrap_either!(&mut self.inner => .any(f))
}
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where
P: FnMut(&Self::Item) -> bool,
{
wrap_either!(&mut self.inner => .find(predicate))
}
fn find_map<B, F>(&mut self, f: F) -> Option<B>
where
F: FnMut(Self::Item) -> Option<B>,
{
wrap_either!(&mut self.inner => .find_map(f))
}
fn position<P>(&mut self, predicate: P) -> Option<usize>
where
P: FnMut(Self::Item) -> bool,
{
wrap_either!(&mut self.inner => .position(predicate))
}
}
impl<L, R> DoubleEndedIterator for IterEither<L, R>
where
L: DoubleEndedIterator,
R: DoubleEndedIterator,
{
fn next_back(&mut self) -> Option<Self::Item> {
Some(map_either!(self.inner, ref mut inner => inner.next_back()?))
}
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
Some(map_either!(self.inner, ref mut inner => inner.nth_back(n)?))
}
fn rfold<Acc, G>(self, init: Acc, f: G) -> Acc
where
G: FnMut(Acc, Self::Item) -> Acc,
{
wrap_either!(self.inner => .rfold(init, f))
}
fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>
where
P: FnMut(&Self::Item) -> bool,
{
wrap_either!(&mut self.inner => .rfind(predicate))
}
}
impl<L, R> ExactSizeIterator for IterEither<L, R>
where
L: ExactSizeIterator,
R: ExactSizeIterator,
{
fn len(&self) -> usize {
for_both!(self.inner, ref inner => inner.len())
}
}
impl<L, R> iter::FusedIterator for IterEither<L, R>
where
L: iter::FusedIterator,
R: iter::FusedIterator,
{
}

1561
vendor/either/src/lib.rs vendored Normal file

File diff suppressed because it is too large Load Diff

69
vendor/either/src/serde_untagged.rs vendored Normal file
View File

@@ -0,0 +1,69 @@
//! Untagged serialization/deserialization support for Either<L, R>.
//!
//! `Either` uses default, externally-tagged representation.
//! However, sometimes it is useful to support several alternative types.
//! For example, we may have a field which is generally Map<String, i32>
//! but in typical cases Vec<String> would suffice, too.
//!
//! ```rust
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use either::Either;
//! use std::collections::HashMap;
//!
//! #[derive(serde::Serialize, serde::Deserialize, Debug)]
//! #[serde(transparent)]
//! struct IntOrString {
//! #[serde(with = "either::serde_untagged")]
//! inner: Either<Vec<String>, HashMap<String, i32>>
//! };
//!
//! // serialization
//! let data = IntOrString {
//! inner: Either::Left(vec!["Hello".to_string()])
//! };
//! // notice: no tags are emitted.
//! assert_eq!(serde_json::to_string(&data)?, r#"["Hello"]"#);
//!
//! // deserialization
//! let data: IntOrString = serde_json::from_str(
//! r#"{"a": 0, "b": 14}"#
//! )?;
//! println!("found {:?}", data);
//! # Ok(())
//! # }
//! ```
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
enum Either<L, R> {
Left(L),
Right(R),
}
pub fn serialize<L, R, S>(this: &super::Either<L, R>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
L: Serialize,
R: Serialize,
{
let untagged = match this {
super::Either::Left(left) => Either::Left(left),
super::Either::Right(right) => Either::Right(right),
};
untagged.serialize(serializer)
}
pub fn deserialize<'de, L, R, D>(deserializer: D) -> Result<super::Either<L, R>, D::Error>
where
D: Deserializer<'de>,
L: Deserialize<'de>,
R: Deserialize<'de>,
{
match Either::deserialize(deserializer) {
Ok(Either::Left(left)) => Ok(super::Either::Left(left)),
Ok(Either::Right(right)) => Ok(super::Either::Right(right)),
Err(error) => Err(error),
}
}

View File

@@ -0,0 +1,74 @@
//! Untagged serialization/deserialization support for Option<Either<L, R>>.
//!
//! `Either` uses default, externally-tagged representation.
//! However, sometimes it is useful to support several alternative types.
//! For example, we may have a field which is generally Map<String, i32>
//! but in typical cases Vec<String> would suffice, too.
//!
//! ```rust
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use either::Either;
//! use std::collections::HashMap;
//!
//! #[derive(serde::Serialize, serde::Deserialize, Debug)]
//! #[serde(transparent)]
//! struct IntOrString {
//! #[serde(with = "either::serde_untagged_optional")]
//! inner: Option<Either<Vec<String>, HashMap<String, i32>>>
//! };
//!
//! // serialization
//! let data = IntOrString {
//! inner: Some(Either::Left(vec!["Hello".to_string()]))
//! };
//! // notice: no tags are emitted.
//! assert_eq!(serde_json::to_string(&data)?, r#"["Hello"]"#);
//!
//! // deserialization
//! let data: IntOrString = serde_json::from_str(
//! r#"{"a": 0, "b": 14}"#
//! )?;
//! println!("found {:?}", data);
//! # Ok(())
//! # }
//! ```
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
enum Either<L, R> {
Left(L),
Right(R),
}
pub fn serialize<L, R, S>(
this: &Option<super::Either<L, R>>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
L: Serialize,
R: Serialize,
{
let untagged = match this {
Some(super::Either::Left(left)) => Some(Either::Left(left)),
Some(super::Either::Right(right)) => Some(Either::Right(right)),
None => None,
};
untagged.serialize(serializer)
}
pub fn deserialize<'de, L, R, D>(deserializer: D) -> Result<Option<super::Either<L, R>>, D::Error>
where
D: Deserializer<'de>,
L: Deserialize<'de>,
R: Deserialize<'de>,
{
match Option::deserialize(deserializer) {
Ok(Some(Either::Left(left))) => Ok(Some(super::Either::Left(left))),
Ok(Some(Either::Right(right))) => Ok(Some(super::Either::Right(right))),
Ok(None) => Ok(None),
Err(error) => Err(error),
}
}