terrified to start testing
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
use std::borrow::Cow;
|
||||
use std::io;
|
||||
use std::rc::Rc;
|
||||
|
||||
use never::Never;
|
||||
use orchid_base::{OrcRes, fmt, is, mk_errv};
|
||||
use orchid_extension::expr::Expr;
|
||||
use orchid_extension::gen_expr::{GExpr, bot, call, new_atom};
|
||||
use orchid_extension::stream_reqs::{ReadLimit, ReadReq};
|
||||
use orchid_extension::{Atomic, ForeignAtom, OwnedAtom, OwnedVariant};
|
||||
use orchid_base::{ReqHandleExt, fmt, is, mk_errv};
|
||||
use orchid_extension::gen_expr::{bot, call, new_atom};
|
||||
use orchid_extension::std_reqs::{ReadLimit, ReadReq, RunCommand};
|
||||
use orchid_extension::{Atomic, Expr, ForeignAtom, OwnedAtom, OwnedVariant, Supports, ToExpr};
|
||||
|
||||
use crate::std::binary::binary_atom::BlobAtom;
|
||||
|
||||
@@ -24,16 +24,22 @@ impl Atomic for ReadStreamCmd {
|
||||
impl OwnedAtom for ReadStreamCmd {
|
||||
type Refs = Never;
|
||||
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(()) }
|
||||
async fn command(self) -> OrcRes<Option<GExpr>> {
|
||||
match self.hand.call(ReadReq(self.limit)).await {
|
||||
}
|
||||
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(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()],
|
||||
)),
|
||||
Some(Err(e)) => Ok(Some(
|
||||
Some(Err(e)) => Ok(
|
||||
call(
|
||||
self.fail,
|
||||
self.fail.clone(),
|
||||
bot(mk_errv(
|
||||
is(e.kind.message()).await,
|
||||
format!("An error occurred while reading: {}", e.message),
|
||||
@@ -41,8 +47,9 @@ impl OwnedAtom for ReadStreamCmd {
|
||||
)),
|
||||
)
|
||||
.await,
|
||||
)),
|
||||
Some(Ok(v)) => Ok(Some(call(self.succ, new_atom(BlobAtom(Rc::new(v)))).await)),
|
||||
}
|
||||
),
|
||||
Some(Ok(v)) => Ok(call(self.succ.clone(), new_atom(BlobAtom(Rc::new(v)))).await),
|
||||
};
|
||||
hand.reply(&req, &Some(ret.to_gen().await.serialize().await)).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
use std::num::NonZero;
|
||||
use std::rc::Rc;
|
||||
|
||||
use orchid_base::{is, mk_errv};
|
||||
use orchid_extension::ForeignAtom;
|
||||
use orchid_extension::expr::Expr;
|
||||
use orchid_extension::func_atom::get_arg;
|
||||
use orchid_extension::gen_expr::new_atom;
|
||||
use orchid_extension::stream_reqs::ReadLimit;
|
||||
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 crate::Int;
|
||||
use crate::std::binary::binary_atom::BlobAtom;
|
||||
use crate::std::stream::stream_cmds::ReadStreamCmd;
|
||||
|
||||
pub fn gen_stream_lib() -> Vec<GenMember> {
|
||||
@@ -30,7 +32,16 @@ pub fn gen_stream_lib() -> Vec<GenMember> {
|
||||
Ok(new_atom(ReadStreamCmd { hand, succ, fail, limit: ReadLimit::Delimiter(end) }))
|
||||
}),
|
||||
fun(true, "read_bytes", async |hand: ForeignAtom, count: Int, succ: Expr, fail: Expr| {
|
||||
Int(todo!())
|
||||
match count.0.try_into().map(NonZero::new) {
|
||||
Ok(Some(nzlen)) =>
|
||||
Ok(new_atom(ReadStreamCmd { hand, succ, fail, limit: ReadLimit::Length(nzlen) })),
|
||||
Ok(None) => Ok(call(succ, new_atom(BlobAtom(Rc::default()))).await),
|
||||
Err(_) => Err(mk_errv(
|
||||
is("Length cannot be negative").await,
|
||||
format!("{} is negative and cannot be used as a length", count.0),
|
||||
[get_arg(1).pos().await],
|
||||
)),
|
||||
}
|
||||
}),
|
||||
]),
|
||||
)])
|
||||
|
||||
Reference in New Issue
Block a user