1
0
Fork 0
forked from wry/wry

all: split reusable components into workspace crates

This commit is contained in:
kossLAN 2026-05-29 09:14:53 -04:00
parent 2a079ed800
commit 657e7ce2f7
No known key found for this signature in database
225 changed files with 7422 additions and 17602 deletions

51
utils/src/tri.rs Normal file
View file

@ -0,0 +1,51 @@
use std::{
future::Future,
marker::PhantomData,
pin::Pin,
task::{Context, Poll},
};
pub trait Try: Sized {
fn tri<F>(f: F) -> Result<(), Self>
where
F: FnOnce() -> Result<(), Self>;
fn tria<F>(f: F) -> Tria<Self, F>
where
F: Future<Output = Result<(), Self>>;
}
impl<E> Try for E {
fn tri<F>(f: F) -> Result<(), Self>
where
F: FnOnce() -> Result<(), Self>,
{
f()
}
fn tria<F>(f: F) -> Tria<E, F>
where
F: Future<Output = Result<(), Self>>,
{
Tria {
f,
_phantom: Default::default(),
}
}
}
pub struct Tria<E, F> {
f: F,
_phantom: PhantomData<E>,
}
impl<E, F> Future for Tria<E, F>
where
F: Future<Output = Result<(), E>>,
{
type Output = Result<(), E>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
unsafe { Pin::new_unchecked(&mut Pin::get_unchecked_mut(self).f).poll(cx) }
}
}