Pending a correct test of request cancellation

This commit is contained in:
2026-04-22 15:58:34 +00:00
parent 60c96964d9
commit 7f8c247d97
31 changed files with 1059 additions and 499 deletions

View File

@@ -48,9 +48,7 @@ pub struct MacroSystemInst {
}
impl System for MacroSystemInst {
type Ctor = MacroSystem;
async fn request<'a>(&self, _: Box<dyn ReqHandle<'a> + 'a>, req: Never) -> Receipt<'a> {
match req {}
}
async fn request(&self, _: Box<dyn ReqHandle>, req: Never) -> Receipt { match req {} }
async fn prelude(&self) -> Vec<Sym> {
vec![
sym!(macros::common::+),

View File

@@ -45,13 +45,9 @@ impl ToExpr for Int {
}
}
impl Supports<ProtocolMethod> for Int {
async fn handle<'a>(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
req: ProtocolMethod,
) -> io::Result<Receipt<'a>> {
async fn handle(&self, hand: Box<dyn ReqHandle>, req: ProtocolMethod) -> io::Result<Receipt> {
match req {
ProtocolMethod::GetTagId(req) => hand.reply(&req, &sym!(std::number::Int).to_api()).await,
ProtocolMethod::GetTagId(req) => hand.reply(&req, sym!(std::number::Int).to_api()).await,
ProtocolMethod::GetImpl(ref req @ GetImpl(key)) => {
let name = Sym::from_api(key).await;
let val = if name == sym!(std::ops::add) {
@@ -65,20 +61,16 @@ impl Supports<ProtocolMethod> for Int {
} else if name == sym!(std::ops::mod) {
sym!(std::number::imod)
} else {
return hand.reply(req, &None).await;
return hand.reply(req, None).await;
};
hand.reply(req, &Some(val.to_expr().await.serialize().await)).await
hand.reply(req, Some(val.to_expr().await.serialize().await)).await
},
}
}
}
impl Supports<ToStringMethod> for Int {
async fn handle<'a>(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
req: ToStringMethod,
) -> io::Result<Receipt<'a>> {
hand.reply(&req, &self.0.to_string()).await
async fn handle(&self, hand: Box<dyn ReqHandle>, req: ToStringMethod) -> io::Result<Receipt> {
hand.reply(&req, self.0.to_string()).await
}
}
@@ -112,13 +104,9 @@ impl ToExpr for Float {
}
}
impl Supports<ProtocolMethod> for Float {
async fn handle<'a>(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
req: ProtocolMethod,
) -> io::Result<Receipt<'a>> {
async fn handle(&self, hand: Box<dyn ReqHandle>, req: ProtocolMethod) -> io::Result<Receipt> {
match req {
ProtocolMethod::GetTagId(req) => hand.reply(&req, &sym!(std::number::Float).to_api()).await,
ProtocolMethod::GetTagId(req) => hand.reply(&req, sym!(std::number::Float).to_api()).await,
ProtocolMethod::GetImpl(ref req @ GetImpl(key)) => {
let name = Sym::from_api(key).await;
let val = if name == sym!(std::ops::add) {
@@ -132,20 +120,16 @@ impl Supports<ProtocolMethod> for Float {
} else if name == sym!(std::ops::mod) {
sym!(std::number::fmod)
} else {
return hand.reply(req, &None).await;
return hand.reply(req, None).await;
};
hand.reply(req, &Some(val.to_expr().await.serialize().await)).await
hand.reply(req, Some(val.to_expr().await.serialize().await)).await
},
}
}
}
impl Supports<ToStringMethod> for Float {
async fn handle<'a>(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
req: ToStringMethod,
) -> io::Result<Receipt<'a>> {
hand.reply(&req, &self.0.to_string()).await
async fn handle(&self, hand: Box<dyn ReqHandle>, req: ToStringMethod) -> io::Result<Receipt> {
hand.reply(&req, self.0.to_string()).await
}
}

View File

@@ -36,16 +36,16 @@ impl OwnedAtom for Tag {
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(self.id.to_api()) }
}
impl Supports<ProtocolMethod> for Tag {
async fn handle<'a>(
async fn handle(
&self,
hand: Box<dyn orchid_base::ReqHandle<'a> + '_>,
hand: Box<dyn orchid_base::ReqHandle>,
req: ProtocolMethod,
) -> std::io::Result<orchid_base::Receipt<'a>> {
) -> std::io::Result<orchid_base::Receipt> {
match req {
ProtocolMethod::GetTagId(req) => hand.reply(&req, &self.id.to_api()).await,
ProtocolMethod::GetTagId(req) => hand.reply(&req, self.id.to_api()).await,
ProtocolMethod::GetImpl(ref req @ GetImpl(key)) =>
hand
.reply(req, &self.impls.get(&Sym::from_api(key).await).map(|expr| expr.handle().ticket()))
.reply(req, self.impls.get(&Sym::from_api(key).await).map(|expr| expr.handle().ticket()))
.await,
}
}
@@ -87,11 +87,11 @@ impl OwnedAtom for Tagged {
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(self.tag.id.to_api()) }
}
impl Supports<ProtocolMethod> for Tagged {
async fn handle<'a>(
async fn handle(
&self,
hand: Box<dyn orchid_base::ReqHandle<'a> + '_>,
hand: Box<dyn orchid_base::ReqHandle>,
req: ProtocolMethod,
) -> io::Result<orchid_base::Receipt<'a>> {
) -> io::Result<orchid_base::Receipt> {
self.tag.handle(hand, req).await
}
}

View File

@@ -40,13 +40,9 @@ impl OwnedAtom for RecordAtom {
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(()) }
}
impl Supports<ProtocolMethod> for RecordAtom {
async fn handle<'a>(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
req: ProtocolMethod,
) -> io::Result<Receipt<'a>> {
async fn handle(&self, hand: Box<dyn ReqHandle>, req: ProtocolMethod) -> io::Result<Receipt> {
match req {
ProtocolMethod::GetTagId(req) => hand.reply(&req, &sym!(std::record::Record).to_api()).await,
ProtocolMethod::GetTagId(req) => hand.reply(&req, sym!(std::record::Record).to_api()).await,
ProtocolMethod::GetImpl(ref req @ GetImpl(key)) => {
let name = Sym::from_api(key).await;
let val = if name == sym!(std::ops::get) {
@@ -54,9 +50,9 @@ impl Supports<ProtocolMethod> for RecordAtom {
} else if name == sym!(std::ops::set) {
sym!(std::record::set)
} else {
return hand.reply(req, &None).await;
return hand.reply(req, None).await;
};
return hand.reply(req, &Some(val.to_expr().await.serialize().await)).await;
return hand.reply(req, Some(val.to_expr().await.serialize().await)).await;
},
}
}

View File

@@ -27,12 +27,12 @@ impl OwnedAtom for SymAtom {
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(SymAtomData(self.0.tok().to_api())) }
}
impl Supports<ToStringMethod> for SymAtom {
async fn handle<'a>(
async fn handle(
&self,
hand: Box<dyn orchid_base::ReqHandle<'a> + '_>,
hand: Box<dyn orchid_base::ReqHandle>,
req: ToStringMethod,
) -> std::io::Result<orchid_base::Receipt<'a>> {
hand.reply(&req, &self.0.to_string()).await
) -> std::io::Result<orchid_base::Receipt> {
hand.reply(&req, self.0.to_string()).await
}
}

View File

@@ -27,6 +27,7 @@ use crate::std::protocol::types::{CreateTag, Tag, Tagged, gen_protocol_lib};
use crate::std::record::record_atom::{CreateRecord, RecordAtom};
use crate::std::record::record_lib::gen_record_lib;
use crate::std::reflection::sym_atom::{CreateSymAtom, SymAtom, gen_sym_lib};
use crate::std::stream::stream_cmds::{ReadStreamCmd, WriteStreamCmd};
use crate::std::stream::stream_lib::gen_stream_lib;
use crate::std::string::str_lexer::StringLexer;
use crate::std::time::{CreateDT, gen_time_lib};
@@ -72,27 +73,25 @@ impl SystemCard for StdSystem {
Some(TupleBuilder::ops()),
Some(Tag::ops()),
Some(Tagged::ops()),
Some(ReadStreamCmd::ops()),
Some(WriteStreamCmd::ops()),
]
}
}
impl System for StdSystem {
type Ctor = Self;
async fn request<'a>(
&self,
xreq: Box<dyn ReqHandle<'a> + 'a>,
req: ReqForSystem<Self>,
) -> Receipt<'a> {
async fn request(&self, xreq: Box<dyn ReqHandle>, req: ReqForSystem<Self>) -> Receipt {
match req {
StdReq::CreateInt(ref req @ CreateInt(int)) =>
xreq.reply(req, &new_atom(int).to_expr().await.serialize().await).await.unwrap(),
xreq.reply(req, new_atom(int).to_expr().await.serialize().await).await.unwrap(),
StdReq::CreateFloat(ref req @ CreateFloat(float)) =>
xreq.reply(req, &new_atom(float).to_expr().await.serialize().await).await.unwrap(),
xreq.reply(req, new_atom(float).to_expr().await.serialize().await).await.unwrap(),
StdReq::CreateDT(ref req @ CreateDT(dt)) =>
xreq.reply(req, &new_atom(dt).to_expr().await.serialize().await).await.unwrap(),
xreq.reply(req, new_atom(dt).to_expr().await.serialize().await).await.unwrap(),
StdReq::CreateTuple(ref req @ CreateTuple(ref items)) => {
let tpl = Tuple(Rc::new(join_all(items.iter().copied().map(Expr::deserialize)).await));
let tk = new_atom(tpl).to_expr().await.serialize().await;
xreq.reply(req, &tk).await.unwrap()
xreq.reply(req, tk).await.unwrap()
},
StdReq::CreateRecord(ref req @ CreateRecord(ref items)) => {
let values =
@@ -100,11 +99,11 @@ impl System for StdSystem {
.await;
let rec = RecordAtom(Rc::new(values.into_iter().collect()));
let tk = new_atom(rec).to_expr().await.serialize().await;
xreq.reply(req, &tk).await.unwrap()
xreq.reply(req, tk).await.unwrap()
},
StdReq::CreateSymAtom(ref req @ CreateSymAtom(sym_tok)) => {
let sym_atom = SymAtom(Sym::from_api(sym_tok).await);
xreq.reply(req, &new_atom(sym_atom).to_expr().await.serialize().await).await.unwrap()
xreq.reply(req, new_atom(sym_atom).to_expr().await.serialize().await).await.unwrap()
},
StdReq::CreateTag(ref req @ CreateTag { name, ref impls }) => {
let tag_atom = Tag {
@@ -119,7 +118,7 @@ impl System for StdSystem {
.collect(),
),
};
xreq.reply(req, &new_atom(tag_atom).to_expr().await.serialize().await).await.unwrap()
xreq.reply(req, new_atom(tag_atom).to_expr().await.serialize().await).await.unwrap()
},
}
}

View File

@@ -3,12 +3,15 @@ use std::io;
use std::rc::Rc;
use never::Never;
use orchid_base::{ReqHandleExt, fmt, is, mk_errv};
use orchid_base::{Receipt, ReqHandle, ReqHandleExt, fmt, is, mk_errv};
use orchid_extension::gen_expr::{bot, call, new_atom, serialize};
use orchid_extension::std_reqs::{ReadLimit, ReadReq, RunCommand};
use orchid_extension::{Atomic, Expr, ForeignAtom, OwnedAtom, OwnedVariant, Supports, ToExpr};
use orchid_extension::std_reqs::{CloseReq, FlushReq, ReadLimit, ReadReq, StartCommand, WriteReq};
use orchid_extension::{
Atomic, Expr, ForeignAtom, MethodSetBuilder, OwnedAtom, OwnedVariant, Supports, ToExpr,
};
use crate::std::binary::binary_atom::BlobAtom;
use crate::std::string::str_atom::StrAtom;
#[derive(Clone, Debug)]
pub struct ReadStreamCmd {
@@ -16,40 +19,99 @@ pub struct ReadStreamCmd {
pub limit: ReadLimit,
pub succ: Expr,
pub fail: Expr,
pub as_str: bool,
}
impl Atomic for ReadStreamCmd {
type Variant = OwnedVariant;
type Data = ();
fn reg_methods() -> MethodSetBuilder<Self> { MethodSetBuilder::new().handle::<StartCommand>() }
}
impl OwnedAtom for ReadStreamCmd {
type Refs = Never;
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(()) }
}
impl Supports<RunCommand> for ReadStreamCmd {
async fn handle<'a>(
&self,
hand: Box<dyn orchid_base::ReqHandle<'a> + '_>,
req: RunCommand,
) -> io::Result<orchid_base::Receipt<'a>> {
let ret = match self.hand.call(ReadReq { limit: self.limit.clone() }).await {
None => Err(mk_errv(
is("Atom is not readable").await,
format!("Expected a readable stream handle, found {}", fmt(&self.hand).await),
[self.hand.pos()],
impl Supports<StartCommand> for ReadStreamCmd {
async fn handle(&self, hand: Box<dyn ReqHandle>, req: StartCommand) -> io::Result<Receipt> {
let ret = 'ret: {
let Some(read_res) = self.hand.call(ReadReq { limit: self.limit.clone() }).await else {
break 'ret Err(mk_errv(
is("Atom is not readable").await,
format!("Expected a readable stream handle, found {}", fmt(&self.hand).await),
[self.hand.pos()],
));
};
let res = match read_res {
Err(e) => Err(mk_errv(
is(e.kind.message()).await,
format!("An error occurred while reading: {}", e.message),
[self.hand.pos(), self.succ.pos().await],
)),
Ok(v) if !self.as_str => Ok(new_atom(BlobAtom(Rc::new(v)))),
Ok(v) => match String::from_utf8(v) {
Ok(s) => Ok(new_atom(StrAtom(Rc::new(s)))),
Err(e) => Err(mk_errv(is("Invalid utf8 in input string").await, e.to_string(), [
self.hand.pos(),
self.succ.pos().await,
])),
},
};
Ok(match res {
Err(e) => call(self.fail.clone(), bot(e)),
Ok(gex) => call(self.succ.clone(), gex),
})
};
hand.reply(&req, Some(serialize(ret.to_gen().await).await)).await
}
}
#[derive(Clone, Debug)]
pub enum WriteAction {
Write(Rc<Vec<u8>>),
Flush,
Close,
}
#[derive(Clone, Debug)]
pub struct WriteStreamCmd {
pub hand: ForeignAtom,
pub action: WriteAction,
pub succ: Expr,
pub fail: Expr,
}
impl Atomic for WriteStreamCmd {
type Variant = OwnedVariant;
type Data = ();
fn reg_methods() -> MethodSetBuilder<Self> { MethodSetBuilder::new().handle::<StartCommand>() }
}
impl OwnedAtom for WriteStreamCmd {
type Refs = Never;
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(()) }
}
impl Supports<StartCommand> for WriteStreamCmd {
async fn handle(&self, hand: Box<dyn ReqHandle>, req: StartCommand) -> io::Result<Receipt> {
let result = match &self.action {
WriteAction::Write(bin) => self.hand.call(WriteReq { data: bin.to_vec() }).await,
WriteAction::Flush => self.hand.call(FlushReq).await,
WriteAction::Close => self.hand.call(CloseReq).await,
};
let cont = match result {
None => bot(mk_errv(
is("Not a writer").await,
format!("{} cannot be written to", fmt(&self.hand).await),
[self.hand.pos(), self.succ.pos().await],
)),
Some(Err(e)) => Ok(
Some(Err(e)) =>
call(
self.fail.clone(),
bot(mk_errv(
is(e.kind.message()).await,
format!("An error occurred while reading: {}", e.message),
format!("An error occurred while writing: {}", e.message),
[self.hand.pos(), self.succ.pos().await],
)),
)
.await,
),
Some(Ok(v)) => Ok(call(self.succ.clone(), new_atom(BlobAtom(Rc::new(v)))).await),
Some(Ok(())) => self.succ.clone().to_gen().await,
};
hand.reply(&req, &Some(serialize(ret.to_gen().await).await)).await
hand.reply(&req, Some(serialize(cont.to_gen().await).await)).await
}
}

View File

@@ -1,22 +1,26 @@
use std::num::NonZero;
use std::rc::Rc;
use itertools::Itertools;
use orchid_base::{is, mk_errv};
use orchid_extension::gen_expr::{call, new_atom};
use orchid_extension::std_reqs::ReadLimit;
use orchid_extension::tree::{GenMember, comments, fun, prefix};
use orchid_extension::{Expr, ForeignAtom, get_arg};
use orchid_extension::{Expr, ForeignAtom, TAtom, get_arg};
use crate::Int;
use crate::std::binary::binary_atom::BlobAtom;
use crate::std::stream::stream_cmds::ReadStreamCmd;
use crate::std::stream::stream_cmds::{ReadStreamCmd, WriteAction, WriteStreamCmd};
use crate::{Int, OrcString};
pub fn gen_stream_lib() -> Vec<GenMember> {
prefix("std", [comments(
["Read from and write to byte streams"],
prefix("stream", [
fun(true, "read_bin", async |hand: ForeignAtom, succ: Expr, fail: Expr| {
new_atom(ReadStreamCmd { hand, succ, fail, limit: ReadLimit::End })
new_atom(ReadStreamCmd { hand, succ, fail, as_str: false, limit: ReadLimit::End })
}),
fun(true, "read_str", async |hand: ForeignAtom, succ: Expr, fail: Expr| {
new_atom(ReadStreamCmd { hand, succ, fail, as_str: true, limit: ReadLimit::End })
}),
fun(true, "read_until", async |hand: ForeignAtom, delim: Int, succ: Expr, fail: Expr| {
let Ok(end) = delim.0.try_into() else {
@@ -29,12 +33,15 @@ pub fn gen_stream_lib() -> Vec<GenMember> {
[get_arg(1).pos().await],
));
};
Ok(new_atom(ReadStreamCmd { hand, succ, fail, limit: ReadLimit::Delimiter(end) }))
let limit = ReadLimit::Delimiter(end);
Ok(new_atom(ReadStreamCmd { hand, succ, fail, as_str: false, limit }))
}),
fun(true, "read_bytes", async |hand: ForeignAtom, count: Int, succ: Expr, fail: Expr| {
match count.0.try_into().map(NonZero::new) {
Ok(Some(nzlen)) =>
Ok(new_atom(ReadStreamCmd { hand, succ, fail, limit: ReadLimit::Length(nzlen) })),
Ok(Some(nzlen)) => {
let limit = ReadLimit::Length(nzlen);
Ok(new_atom(ReadStreamCmd { hand, succ, fail, as_str: false, limit }))
},
Ok(None) => Ok(call(succ, new_atom(BlobAtom(Rc::default()))).await),
Err(_) => Err(mk_errv(
is("Length cannot be negative").await,
@@ -43,6 +50,28 @@ pub fn gen_stream_lib() -> Vec<GenMember> {
)),
}
}),
fun(true, "read_line", async |hand: ForeignAtom, succ: Expr, fail: Expr| {
const LIMIT_BR: ReadLimit = ReadLimit::Delimiter(b'\n');
new_atom(ReadStreamCmd { hand, succ, fail, as_str: true, limit: LIMIT_BR })
}),
fun(true, "write_str", async |hand: ForeignAtom, str: OrcString, succ: Expr, fail: Expr| {
let action = WriteAction::Write(Rc::new(str.get_string().await.bytes().collect_vec()));
new_atom(WriteStreamCmd { hand, action, succ, fail })
}),
fun(
true,
"write_bin",
async |hand: ForeignAtom, bin: TAtom<BlobAtom>, succ: Expr, fail: Expr| {
let action = WriteAction::Write(bin.own().await.0.clone());
new_atom(WriteStreamCmd { hand, action, succ, fail })
},
),
fun(true, "flush", async |hand: ForeignAtom, succ: Expr, fail: Expr| {
new_atom(WriteStreamCmd { hand, action: WriteAction::Flush, succ, fail })
}),
fun(true, "close", async |hand: ForeignAtom, succ: Expr, fail: Expr| {
new_atom(WriteStreamCmd { hand, action: WriteAction::Close, succ, fail })
}),
]),
)])
}

View File

@@ -28,7 +28,7 @@ impl AtomMethod for StringGetValMethod {
}
#[derive(Clone)]
pub struct StrAtom(Rc<String>);
pub struct StrAtom(pub(crate) Rc<String>);
impl Atomic for StrAtom {
type Variant = OwnedVariant;
type Data = ();
@@ -60,39 +60,39 @@ impl OwnedAtom for StrAtom {
}
}
impl Supports<StringGetValMethod> for StrAtom {
async fn handle<'a>(
async fn handle(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
hand: Box<dyn ReqHandle>,
req: StringGetValMethod,
) -> io::Result<Receipt<'a>> {
hand.reply(&req, &self.0).await
) -> io::Result<Receipt> {
hand.reply(&req, self.0.clone()).await
}
}
impl Supports<ToStringMethod> for StrAtom {
async fn handle<'a>(
async fn handle(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
hand: Box<dyn ReqHandle>,
req: ToStringMethod,
) -> io::Result<Receipt<'a>> {
hand.reply(&req, &self.0).await
) -> io::Result<Receipt> {
hand.reply(&req, self.0.to_string()).await
}
}
impl Supports<ProtocolMethod> for StrAtom {
async fn handle<'a>(
async fn handle(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
hand: Box<dyn ReqHandle>,
req: ProtocolMethod,
) -> io::Result<Receipt<'a>> {
) -> io::Result<Receipt> {
match req {
ProtocolMethod::GetTagId(req) => hand.reply(&req, &sym!(std::string::StrAtom).to_api()).await,
ProtocolMethod::GetTagId(req) => hand.reply(&req, sym!(std::string::StrAtom).to_api()).await,
ProtocolMethod::GetImpl(ref req @ GetImpl(key)) => {
let name = Sym::from_api(key).await;
let val = if name == sym!(std::ops::add) {
sym!(std::string::concat)
} else {
return hand.reply(req, &None).await;
return hand.reply(req, None).await;
};
hand.reply(req, &Some(val.to_expr().await.serialize().await)).await
hand.reply(req, Some(val.to_expr().await.serialize().await)).await
},
}
}
@@ -130,31 +130,31 @@ impl TryFromExpr for IntStrAtom {
}
}
impl Supports<ToStringMethod> for IntStrAtom {
async fn handle<'a>(
async fn handle(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
hand: Box<dyn ReqHandle>,
req: ToStringMethod,
) -> io::Result<Receipt<'a>> {
hand.reply(&req, &self.0.rc()).await
) -> io::Result<Receipt> {
hand.reply(&req, self.0.to_string()).await
}
}
impl Supports<ProtocolMethod> for IntStrAtom {
async fn handle<'a>(
async fn handle(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
hand: Box<dyn ReqHandle>,
req: ProtocolMethod,
) -> io::Result<Receipt<'a>> {
) -> io::Result<Receipt> {
match req {
ProtocolMethod::GetTagId(req) =>
hand.reply(&req, &sym!(std::string::IntStrAtom).to_api()).await,
hand.reply(&req, sym!(std::string::IntStrAtom).to_api()).await,
ProtocolMethod::GetImpl(ref req @ GetImpl(key)) => {
let name = Sym::from_api(key).await;
let val = if name == sym!(std::ops::add) {
sym!(std::string::concat)
} else {
return hand.reply(req, &None).await;
return hand.reply(req, None).await;
};
hand.reply(req, &Some(val.to_expr().await.serialize().await)).await
hand.reply(req, Some(val.to_expr().await.serialize().await)).await
},
}
}

View File

@@ -8,7 +8,7 @@ use orchid_api_derive::{Coding, Hierarchy};
use orchid_api_traits::Request;
use orchid_base::{Numeric, OrcRes, Receipt, ReqHandle, ReqHandleExt};
use orchid_extension::gen_expr::{GExpr, call, new_atom, serialize};
use orchid_extension::std_reqs::{AsInstant, RunCommand};
use orchid_extension::std_reqs::{AsInstant, StartCommand};
use orchid_extension::tree::{GenMember, fun, prefix};
use orchid_extension::{
Atomic, Expr, MethodSetBuilder, OwnedAtom, OwnedVariant, Supports, TAtom, ThinAtom, ThinVariant,
@@ -55,12 +55,8 @@ impl OwnedAtom for InstantAtom {
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(()) }
}
impl Supports<AsInstant> for InstantAtom {
async fn handle<'a>(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
req: AsInstant,
) -> std::io::Result<Receipt<'a>> {
hand.reply(&req, &self.0).await
async fn handle(&self, hand: Box<dyn ReqHandle>, req: AsInstant) -> std::io::Result<Receipt> {
hand.reply(&req, self.0).await
}
}
@@ -69,20 +65,16 @@ struct Now(Expr);
impl Atomic for Now {
type Variant = OwnedVariant;
type Data = ();
fn reg_methods() -> MethodSetBuilder<Self> { MethodSetBuilder::new().handle::<RunCommand>() }
fn reg_methods() -> MethodSetBuilder<Self> { MethodSetBuilder::new().handle::<StartCommand>() }
}
impl OwnedAtom for Now {
type Refs = Never;
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(()) }
}
impl Supports<RunCommand> for Now {
async fn handle<'a>(
&self,
hand: Box<dyn ReqHandle<'a> + '_>,
req: RunCommand,
) -> io::Result<Receipt<'a>> {
impl Supports<StartCommand> for Now {
async fn handle(&self, hand: Box<dyn ReqHandle>, req: StartCommand) -> io::Result<Receipt> {
let cont = serialize(call(self.0.clone(), new_atom(InstantAtom(Utc::now()))).await).await;
hand.reply(&req, &Some(cont)).await
hand.reply(&req, Some(cont)).await
}
}

View File

@@ -48,13 +48,13 @@ impl OwnedAtom for Tuple {
}
}
impl Supports<ProtocolMethod> for Tuple {
async fn handle<'a>(
async fn handle(
&self,
hand: Box<dyn orchid_base::ReqHandle<'a> + '_>,
hand: Box<dyn orchid_base::ReqHandle>,
req: ProtocolMethod,
) -> std::io::Result<orchid_base::Receipt<'a>> {
) -> std::io::Result<orchid_base::Receipt> {
match req {
ProtocolMethod::GetTagId(req) => hand.reply(&req, &sym!(std::tuple).to_api()).await,
ProtocolMethod::GetTagId(req) => hand.reply(&req, sym!(std::tuple).to_api()).await,
ProtocolMethod::GetImpl(ref req @ GetImpl(key)) => {
let name = Sym::from_api(key).await;
let val = if name == sym!(std::ops::get) {
@@ -62,9 +62,9 @@ impl Supports<ProtocolMethod> for Tuple {
} else if name == sym!(std::ops::set) {
sym!(std::tuple::set)
} else {
return hand.reply(req, &None).await;
return hand.reply(req, None).await;
};
hand.reply(req, &Some(val.to_expr().await.serialize().await)).await
hand.reply(req, Some(val.to_expr().await.serialize().await)).await
},
}
}