forked from Orchid/orchid
Method refactor now compiles
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
use std::borrow::Cow;
|
||||
use std::io;
|
||||
use std::ops::Deref;
|
||||
use std::pin::Pin;
|
||||
use std::rc::Rc;
|
||||
|
||||
use futures::AsyncWrite;
|
||||
use orchid_api_derive::Coding;
|
||||
use orchid_api_derive::{Coding, Hierarchy};
|
||||
use orchid_api_traits::{Encode, Request};
|
||||
use orchid_base::error::{OrcRes, mk_errv};
|
||||
use orchid_base::format::{FmtCtx, FmtUnit};
|
||||
use orchid_base::interner::{IStr, es, is};
|
||||
use orchid_base::name::Sym;
|
||||
use orchid_base::reqnot::{Receipt, ReqHandle, ReqHandleExt};
|
||||
use orchid_base::sym;
|
||||
use orchid_extension::atom::{AtomMethod, Atomic, MethodSetBuilder, Supports, TAtom};
|
||||
use orchid_extension::atom_owned::{DeserializeCtx, OwnedAtom, OwnedVariant};
|
||||
@@ -17,10 +19,10 @@ use orchid_extension::conv::TryFromExpr;
|
||||
use orchid_extension::expr::Expr;
|
||||
use orchid_extension::gen_expr::sym_ref;
|
||||
|
||||
use crate::std::protocol::types::{GetImplMethod, GetTagIdMethod};
|
||||
use crate::std::protocol::types::{GetImpl, ProtocolMethod};
|
||||
use crate::std::string::to_string::ToStringMethod;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Coding)]
|
||||
#[derive(Copy, Clone, Debug, Coding, Hierarchy)]
|
||||
pub struct StringGetValMethod;
|
||||
impl Request for StringGetValMethod {
|
||||
type Response = Rc<String>;
|
||||
@@ -38,8 +40,7 @@ impl Atomic for StrAtom {
|
||||
MethodSetBuilder::new()
|
||||
.handle::<StringGetValMethod>()
|
||||
.handle::<ToStringMethod>()
|
||||
.handle::<GetTagIdMethod>()
|
||||
.handle::<GetImplMethod>()
|
||||
.handle::<ProtocolMethod>()
|
||||
}
|
||||
}
|
||||
impl StrAtom {
|
||||
@@ -63,29 +64,41 @@ impl OwnedAtom for StrAtom {
|
||||
}
|
||||
}
|
||||
impl Supports<StringGetValMethod> for StrAtom {
|
||||
async fn handle(&self, _: StringGetValMethod) -> <StringGetValMethod as Request>::Response {
|
||||
self.0.clone()
|
||||
async fn handle<'a>(
|
||||
&self,
|
||||
hand: Box<dyn ReqHandle<'a> + '_>,
|
||||
req: StringGetValMethod,
|
||||
) -> io::Result<Receipt<'a>> {
|
||||
hand.reply(&req, &self.0).await
|
||||
}
|
||||
}
|
||||
impl Supports<ToStringMethod> for StrAtom {
|
||||
async fn handle(&self, _: ToStringMethod) -> <ToStringMethod as Request>::Response {
|
||||
self.0.as_str().to_string()
|
||||
async fn handle<'a>(
|
||||
&self,
|
||||
hand: Box<dyn ReqHandle<'a> + '_>,
|
||||
req: ToStringMethod,
|
||||
) -> io::Result<Receipt<'a>> {
|
||||
hand.reply(&req, &self.0).await
|
||||
}
|
||||
}
|
||||
impl Supports<GetTagIdMethod> for StrAtom {
|
||||
async fn handle(&self, _: GetTagIdMethod) -> <GetTagIdMethod as Request>::Response {
|
||||
sym!(std::string::StrAtom).to_api()
|
||||
}
|
||||
}
|
||||
impl Supports<GetImplMethod> for StrAtom {
|
||||
async fn handle(&self, req: GetImplMethod) -> <GetImplMethod as Request>::Response {
|
||||
let name = Sym::from_api(req.0).await;
|
||||
let val = if name == sym!(std::ops::add) {
|
||||
sym_ref(sym!(std::string::concat))
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
Some(val.create().await.serialize().await)
|
||||
impl Supports<ProtocolMethod> for StrAtom {
|
||||
async fn handle<'a>(
|
||||
&self,
|
||||
hand: Box<dyn ReqHandle<'a> + '_>,
|
||||
req: ProtocolMethod,
|
||||
) -> io::Result<Receipt<'a>> {
|
||||
match req {
|
||||
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_ref(sym!(std::string::concat))
|
||||
} else {
|
||||
return hand.reply(req, &None).await;
|
||||
};
|
||||
hand.reply(req, &Some(val.create().await.serialize().await)).await
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,10 +108,7 @@ impl Atomic for IntStrAtom {
|
||||
type Variant = OwnedVariant;
|
||||
type Data = orchid_api::TStr;
|
||||
fn reg_reqs() -> MethodSetBuilder<Self> {
|
||||
MethodSetBuilder::new()
|
||||
.handle::<GetTagIdMethod>()
|
||||
.handle::<GetImplMethod>()
|
||||
.handle::<ToStringMethod>()
|
||||
MethodSetBuilder::new().handle::<ProtocolMethod>().handle::<ToStringMethod>()
|
||||
}
|
||||
}
|
||||
impl From<IStr> for IntStrAtom {
|
||||
@@ -124,27 +134,35 @@ impl TryFromExpr for IntStrAtom {
|
||||
}
|
||||
}
|
||||
impl Supports<ToStringMethod> for IntStrAtom {
|
||||
async fn handle(&self, _: ToStringMethod) -> <ToStringMethod as Request>::Response {
|
||||
self.0.to_string()
|
||||
async fn handle<'a>(
|
||||
&self,
|
||||
hand: Box<dyn ReqHandle<'a> + '_>,
|
||||
req: ToStringMethod,
|
||||
) -> io::Result<Receipt<'a>> {
|
||||
hand.reply(&req, &self.0.rc()).await
|
||||
}
|
||||
}
|
||||
impl Supports<GetTagIdMethod> for IntStrAtom {
|
||||
async fn handle(&self, _: GetTagIdMethod) -> <GetTagIdMethod as Request>::Response {
|
||||
sym!(std::string::IntStrAtom).to_api()
|
||||
impl Supports<ProtocolMethod> for IntStrAtom {
|
||||
async fn handle<'a>(
|
||||
&self,
|
||||
hand: Box<dyn ReqHandle<'a> + '_>,
|
||||
req: ProtocolMethod,
|
||||
) -> io::Result<Receipt<'a>> {
|
||||
match req {
|
||||
ProtocolMethod::GetTagId(req) =>
|
||||
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_ref(sym!(std::string::concat))
|
||||
} else {
|
||||
return hand.reply(req, &None).await;
|
||||
};
|
||||
hand.reply(req, &Some(val.create().await.serialize().await)).await
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Supports<GetImplMethod> for IntStrAtom {
|
||||
async fn handle(&self, req: GetImplMethod) -> <GetImplMethod as Request>::Response {
|
||||
let name = Sym::from_api(req.0).await;
|
||||
let val = if name == sym!(std::ops::add) {
|
||||
sym_ref(sym!(std::string::concat))
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
Some(val.create().await.serialize().await)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct OrcString {
|
||||
kind: OrcStringKind,
|
||||
|
||||
Reference in New Issue
Block a user