feat: Add platform arg to force building a specific architecture

This commit is contained in:
Gerald Pinder 2024-09-29 17:00:37 -04:00
parent 20d1950530
commit 75eae89e4a
22 changed files with 408 additions and 71 deletions

View file

@ -1,26 +1,8 @@
use std::{
borrow::Cow,
ffi::{OsStr, OsString},
path::{Path, PathBuf},
};
use std::{borrow::Cow, ffi::OsStr, path::Path};
trait PrivateTrait<T: ToOwned + ?Sized> {}
trait PrivateTrait<T: ?Sized>: IntoIterator {}
macro_rules! impl_private_trait {
($lt:lifetime, $type:ty) => {
impl<$lt, T> PrivateTrait<$type> for T where T: AsRef<[&$lt $type]> {}
};
($type:ty) => {
impl<T> PrivateTrait<$type> for T where T: AsRef<[$type]> {}
};
}
impl_private_trait!(String);
impl_private_trait!('a, str);
impl_private_trait!(PathBuf);
impl_private_trait!('a, Path);
impl_private_trait!(OsString);
impl_private_trait!('a, OsStr);
impl<T, R> PrivateTrait<R> for T where T: IntoIterator {}
#[allow(private_bounds)]
pub trait CowCollecter<'a, IN, OUT>: PrivateTrait<IN>
@ -28,35 +10,91 @@ where
IN: ToOwned + ?Sized,
OUT: ToOwned + ?Sized,
{
fn to_cow_vec(&'a self) -> Vec<Cow<'a, OUT>>;
fn collect_cow_vec(&'a self) -> Vec<Cow<'a, OUT>>;
}
impl<'a, T, R> CowCollecter<'a, R, R> for T
where
T: AsRef<[R]> + IntoIterator,
R: ToOwned,
{
fn collect_cow_vec(&'a self) -> Vec<Cow<'a, R>> {
self.as_ref().iter().map(Cow::Borrowed).collect()
}
}
macro_rules! impl_cow_collector {
($type:ty) => {
impl<'a, T> CowCollecter<'a, $type, $type> for T
impl<'a, T, R> CowCollecter<'a, R, $type> for T
where
T: AsRef<[&'a $type]>,
T: AsRef<[R]> + IntoIterator,
R: AsRef<$type> + ToOwned + 'a,
{
fn to_cow_vec(&'a self) -> Vec<Cow<'a, $type>> {
self.as_ref().iter().map(|v| Cow::Borrowed(*v)).collect()
}
}
};
($in:ty, $out:ty) => {
impl<'a, T> CowCollecter<'a, $in, $out> for T
where
T: AsRef<[$in]>,
{
fn to_cow_vec(&'a self) -> Vec<Cow<'a, $out>> {
self.as_ref().iter().map(Cow::from).collect()
fn collect_cow_vec(&'a self) -> Vec<Cow<'a, $type>> {
self.as_ref()
.iter()
.map(|v| v.as_ref())
.map(Cow::from)
.collect()
}
}
};
}
impl_cow_collector!(String, str);
impl_cow_collector!(str);
impl_cow_collector!(PathBuf, Path);
impl_cow_collector!(Path);
impl_cow_collector!(OsString, OsStr);
impl_cow_collector!(OsStr);
#[allow(private_bounds)]
pub trait AsRefCollector<'a, IN, OUT>: PrivateTrait<IN>
where
IN: ?Sized,
OUT: ?Sized,
{
fn collect_as_ref_vec(&'a self) -> Vec<&'a OUT>;
}
impl<'a, T, R> AsRefCollector<'a, R, R> for T
where
T: AsRef<[R]> + IntoIterator,
{
fn collect_as_ref_vec(&'a self) -> Vec<&'a R> {
self.as_ref().iter().collect()
}
}
macro_rules! impl_asref_collector {
($type:ty) => {
impl<'a, T, R> AsRefCollector<'a, R, $type> for T
where
T: AsRef<[R]> + IntoIterator,
R: AsRef<$type> + 'a,
{
fn collect_as_ref_vec(&'a self) -> Vec<&'a $type> {
self.as_ref().iter().map(AsRef::as_ref).collect()
}
}
};
}
impl_asref_collector!(str);
impl_asref_collector!(Path);
impl_asref_collector!(OsStr);
#[allow(private_bounds)]
pub trait IntoCollector<IN, OUT>: PrivateTrait<IN>
where
IN: Into<OUT>,
{
fn collect_into_vec(self) -> Vec<OUT>;
}
impl<T, U, R> IntoCollector<U, R> for T
where
T: IntoIterator<Item = U>,
U: Into<R>,
{
fn collect_into_vec(self) -> Vec<R> {
self.into_iter().map(Into::into).collect()
}
}