Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions macros/src/throws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn make_fn_block(ty: &syn::Type, inner: &syn::Block) -> syn::Block {
let __ret = { #inner };

#[allow(unreachable_code)]
<#ty as ::culpa::__internal::_Succeed>::from_ok(__ret)
::core::iter::Iterator::try_fold::<_, _, #ty>(&mut ::core::iter::empty::<::core::convert::Infallible>(), __ret, |_, x| match x {})
}
}})
.unwrap();
Expand All @@ -155,9 +155,9 @@ fn make_fn_block(ty: &syn::Type, inner: &syn::Block) -> syn::Block {
}

fn ok(ty: &syn::Type, expr: &syn::Expr) -> syn::Expr {
syn::parse2(quote::quote!(<#ty as ::culpa::__internal::_Succeed>::from_ok(#expr))).unwrap()
syn::parse2(quote::quote!(::core::iter::Iterator::try_fold::<_, _, #ty>(&mut ::core::iter::empty::<::core::convert::Infallible>(), #expr, |_, x| match x {}))).unwrap()
}

fn ok_unit(ty: &syn::Type) -> syn::Expr {
syn::parse2(quote::quote!(<#ty as ::culpa::__internal::_Succeed>::from_ok(()))).unwrap()
syn::parse2(quote::quote!(::core::iter::Iterator::try_fold::<_, _, #ty>(&mut ::core::iter::empty::<::core::convert::Infallible>(), (), |_, x| match x {}))).unwrap()
}
43 changes: 0 additions & 43 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ macro_rules! throw {

#[doc(hidden)]
pub mod __internal {
pub trait _Succeed {
type Ok;
fn from_ok(ok: Self::Ok) -> Self;
}

pub trait _Throw {
type Error;
fn from_error(error: Self::Error) -> Self;
Expand All @@ -122,31 +117,13 @@ pub mod __internal {
mod stable {
use core::task::Poll;

impl<T, E> super::_Succeed for Result<T, E> {
type Ok = T;
fn from_ok(ok: T) -> Self {
Ok(ok)
}
}

impl<T, E> super::_Throw for Result<T, E> {
type Error = E;
fn from_error(error: Self::Error) -> Self {
Err(error)
}
}

impl<T, E> super::_Succeed for Poll<Result<T, E>> {
type Ok = Poll<T>;

fn from_ok(ok: Self::Ok) -> Self {
match ok {
Poll::Ready(ok) => Poll::Ready(Ok(ok)),
Poll::Pending => Poll::Pending,
}
}
}

impl<T, E> super::_Throw for Poll<Result<T, E>> {
type Error = E;

Expand All @@ -155,33 +132,13 @@ pub mod __internal {
}
}

impl<T, E> super::_Succeed for Poll<Option<Result<T, E>>> {
type Ok = Poll<Option<T>>;

fn from_ok(ok: Self::Ok) -> Self {
match ok {
Poll::Ready(Some(ok)) => Poll::Ready(Some(Ok(ok))),
Poll::Ready(None) => Poll::Ready(None),
Poll::Pending => Poll::Pending,
}
}
}

impl<T, E> super::_Throw for Poll<Option<Result<T, E>>> {
type Error = E;

fn from_error(error: Self::Error) -> Self {
Poll::Ready(Some(Err(error)))
}
}

impl<T> super::_Succeed for Option<T> {
type Ok = T;

fn from_ok(ok: Self::Ok) -> Self {
Some(ok)
}
}
}
}

Expand Down