terrified to start testing
This commit is contained in:
@@ -2,19 +2,20 @@ use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
use dyn_clone::DynClone;
|
||||
use futures::future::FusedFuture;
|
||||
use never::Never;
|
||||
use orchid_base::{Format, OrcErrv, OrcRes, Pos, fmt, is, mk_errv};
|
||||
use trait_set::trait_set;
|
||||
|
||||
use crate::atom::{AtomicFeatures, ForeignAtom, TAtom};
|
||||
use crate::expr::{Expr, ExprKind};
|
||||
use crate::gen_expr::{GExpr, bot};
|
||||
use crate::{AtomicFeatures, Expr, ExprKind, ForeignAtom, TAtom};
|
||||
|
||||
/// Attempt to cast a generic Orchid expression reference to a concrete value.
|
||||
/// Note that this cannot evaluate the expression, and if it is not already
|
||||
/// evaluated, it will simply fail. Use [crate::ExecHandle::exec] inside
|
||||
/// [crate::exec] to wait for an expression to be evaluated
|
||||
/// Values that may be converted from certain specific Orchid expressions
|
||||
pub trait TryFromExpr: Sized {
|
||||
/// Attempt to cast a generic Orchid expression reference to a concrete value.
|
||||
/// Note that this cannot evaluate the expression, and if it is not already
|
||||
/// evaluated, it will simply fail. Use [crate::ExecHandle::exec] inside
|
||||
/// [crate::exec] to wait for an expression to be evaluated
|
||||
fn try_from_expr(expr: Expr) -> impl Future<Output = OrcRes<Self>>;
|
||||
}
|
||||
|
||||
@@ -58,6 +59,9 @@ impl<A: AtomicFeatures> TryFromExpr for TAtom<A> {
|
||||
|
||||
/// Values that are convertible to an Orchid expression. This could mean that
|
||||
/// the value owns an [Expr] or it may involve more complex operations
|
||||
///
|
||||
/// [ToExpr] is also implemented for [orchid_base::Sym] where it converts to a
|
||||
/// reference to the constant by that name
|
||||
pub trait ToExpr {
|
||||
/// Inline the value in an expression returned from a function or included in
|
||||
/// the const tree returned by [crate::System::env]
|
||||
@@ -69,6 +73,8 @@ pub trait ToExpr {
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper for a future that implements [ToExpr]
|
||||
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct ToExprFuture<F>(pub F);
|
||||
|
||||
impl<F: Future<Output: ToExpr>> ToExpr for ToExprFuture<F> {
|
||||
@@ -78,6 +84,9 @@ impl<F: Future<Output: ToExpr>> ToExpr for ToExprFuture<F> {
|
||||
self.0.await.to_expr().await
|
||||
}
|
||||
}
|
||||
impl<F: FusedFuture> FusedFuture for ToExprFuture<F> {
|
||||
fn is_terminated(&self) -> bool { self.0.is_terminated() }
|
||||
}
|
||||
impl<F: Future> Future for ToExprFuture<F> {
|
||||
type Output = F::Output;
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
|
||||
|
||||
Reference in New Issue
Block a user