Orchid-base uses task-local context.

Everything else is broken at the moment.
This commit is contained in:
2025-12-14 17:17:43 +01:00
parent 8753d4c751
commit 0b2b05d44e
22 changed files with 463 additions and 1082 deletions

View File

@@ -3,6 +3,7 @@ use std::cmp::Ordering;
use std::convert::Infallible;
use std::future::Future;
use std::iter;
use std::marker::PhantomData;
use std::rc::Rc;
use std::str::FromStr;
@@ -11,7 +12,6 @@ use itertools::{Itertools, chain};
use never::Never;
use regex::Regex;
use crate::interner::Interner;
use crate::{api, match_mapping};
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
@@ -300,16 +300,15 @@ pub fn take_first(unit: &FmtUnit, bounded: bool) -> String {
fill_slots(&first.elements, &unit.subs, 0, bounded)
}
pub async fn take_first_fmt(v: &(impl Format + ?Sized), i: &Interner) -> String {
take_first(&v.print(&FmtCtxImpl { i }).await, false)
pub async fn take_first_fmt(v: &(impl Format + ?Sized)) -> String {
take_first(&v.print(&FmtCtxImpl { _foo: PhantomData }).await, false)
}
pub struct FmtCtxImpl<'a> {
pub i: &'a Interner,
_foo: PhantomData<&'a ()>,
}
pub trait FmtCtx {
fn i(&self) -> &Interner;
// fn print_as(&self, p: &(impl Format + ?Sized)) -> impl Future<Output =
// String> where Self: Sized {
// async {
@@ -319,9 +318,7 @@ pub trait FmtCtx {
// }
// }
}
impl FmtCtx for FmtCtxImpl<'_> {
fn i(&self) -> &Interner { self.i }
}
impl FmtCtx for FmtCtxImpl<'_> {}
pub trait Format {
#[must_use]
@@ -332,13 +329,10 @@ impl Format for Never {
}
/// Format with default strategy. Currently equal to [take_first_fmt]
pub async fn fmt(v: &(impl Format + ?Sized), i: &Interner) -> String { take_first_fmt(v, i).await }
pub async fn fmt(v: &(impl Format + ?Sized)) -> String { take_first_fmt(v).await }
/// Format a sequence with default strategy. Currently equal to [take_first_fmt]
pub async fn fmt_v<F: Format + ?Sized, R: Borrow<F>>(
v: impl IntoIterator<Item = R>,
i: &Interner,
) -> impl Iterator<Item = String> {
join_all(v.into_iter().map(|f| async move { take_first_fmt(f.borrow(), i).await }))
.await
.into_iter()
join_all(v.into_iter().map(|f| async move { take_first_fmt(f.borrow()).await })).await.into_iter()
}