Skip to content

Commit

Permalink
Release 0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Flowneee committed Aug 20, 2023
1 parent d48ba90 commit d6644e1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased] - XXXX-XX-XX
## [0.0.6] - 2023-08-20
### Added
- `TupleResponse` type for decoding `eval` and `call` responses.

Expand Down
11 changes: 5 additions & 6 deletions src/client/executor_ext.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::borrow::Cow;

use async_trait::async_trait;
use futures::{future::BoxFuture, FutureExt, TryFutureExt};
use rmpv::Value;
Expand Down Expand Up @@ -41,10 +39,10 @@ pub trait ExecutorExt: Executor {
async fn eval<A, I>(&self, expr: I, args: A) -> Result<TupleResponse>
where
A: Tuple + Send,
I: Into<Cow<'static, str>> + Send,
I: AsRef<str> + Send + Sync,
{
Ok(TupleResponse(
self.send_request(Eval::new(expr, args)).await?,
self.send_request(Eval::new(expr.as_ref(), args)).await?,
))
}

Expand All @@ -54,10 +52,11 @@ pub trait ExecutorExt: Executor {
async fn call<A, I>(&self, function_name: I, args: A) -> Result<TupleResponse>
where
A: Tuple + Send,
I: Into<Cow<'static, str>> + Send,
I: AsRef<str> + Send + Sync,
{
Ok(TupleResponse(
self.send_request(Call::new(function_name, args)).await?,
self.send_request(Call::new(function_name.as_ref(), args))
.await?,
))
}

Expand Down
16 changes: 8 additions & 8 deletions src/codec/request/call.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, io::Write};
use std::io::Write;

use crate::{
codec::{
Expand All @@ -12,12 +12,12 @@ use crate::{
use super::Request;

#[derive(Clone, Debug)]
pub(crate) struct Call<T> {
pub function_name: Cow<'static, str>,
pub(crate) struct Call<'a, T> {
pub function_name: &'a str,
pub tuple: T,
}

impl<T: Tuple> Request for Call<T> {
impl<'a, T: Tuple> Request for Call<'a, T> {
fn request_type() -> RequestType
where
Self: Sized,
Expand All @@ -28,16 +28,16 @@ impl<T: Tuple> Request for Call<T> {
// NOTE: `&mut buf: mut` is required since I don't get why compiler complain
fn encode(&self, mut buf: &mut dyn Write) -> Result<(), EncodingError> {
rmp::encode::write_map_len(&mut buf, 2)?;
write_kv_str(buf, keys::FUNCTION_NAME, self.function_name.as_ref())?;
write_kv_str(buf, keys::FUNCTION_NAME, self.function_name)?;
write_kv_tuple(buf, keys::TUPLE, &self.tuple)?;
Ok(())
}
}

impl<T> Call<T> {
pub(crate) fn new(function_name: impl Into<Cow<'static, str>>, args: T) -> Self {
impl<'a, T> Call<'a, T> {
pub(crate) fn new(function_name: &'a str, args: T) -> Self {
Self {
function_name: function_name.into(),
function_name,
tuple: args,
}
}
Expand Down
20 changes: 8 additions & 12 deletions src/codec/request/eval.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, io::Write};
use std::io::Write;

use crate::{
codec::{
Expand All @@ -12,12 +12,12 @@ use crate::{
use super::Request;

#[derive(Clone, Debug)]
pub(crate) struct Eval<T> {
pub expr: Cow<'static, str>,
pub(crate) struct Eval<'a, T> {
pub expr: &'a str,
pub tuple: T,
}

impl<T: Tuple> Request for Eval<T> {
impl<'a, T: Tuple> Request for Eval<'a, T> {
fn request_type() -> RequestType
where
Self: Sized,
Expand All @@ -28,18 +28,14 @@ impl<T: Tuple> Request for Eval<T> {
// NOTE: `&mut buf: mut` is required since I don't get why compiler complain
fn encode(&self, mut buf: &mut dyn Write) -> Result<(), EncodingError> {
rmp::encode::write_map_len(&mut buf, 2)?;
write_kv_str(buf, keys::EXPR, self.expr.as_ref())?;
write_kv_str(buf, keys::EXPR, self.expr)?;
write_kv_tuple(buf, keys::TUPLE, &self.tuple)?;
Ok(())
}
}

impl<T> Eval<T> {
// TODO: introduce some convenient way to pass arguments
pub fn new(expr: impl Into<Cow<'static, str>>, args: T) -> Self {
Self {
expr: expr.into(),
tuple: args,
}
impl<'a, T> Eval<'a, T> {
pub fn new(expr: &'a str, args: T) -> Self {
Self { expr, tuple: args }
}
}

0 comments on commit d6644e1

Please sign in to comment.