-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Async support #139
Comments
@hamidrezakp There is nothing to make async, the whole process is CPU-bound, and fast. What is your use case? |
I meant we support reading from polllable sources like TCP/IP or sockets. |
I see, no there are no plans and no capacity to implement the support, but I am ready to review a PR if anyone will contribute the support with tests and documentation |
Great, Probably i can work on it in the next week. |
@hamidrezakp hi, are you going to finish it? |
Hey, This change is breaking and it makes a bad user experience, because with this approach we would have two set of traits, blocking and non-blocking, which is quite bad and no one is gonna use it. Unless you or somebody else have a better workaround or idea to add async support, i think i may create a crate like |
Why do we need a new trait bound? Can you share your code, please? I am not very familiar with async Rust. I guess we could just add an async crate feature and expose a new set of async functions something like @frol what do you think about this? |
Here is the code i came up for serialization: #[async_trait::async_trait]
pub trait BorshSerialize {
async fn serialize<W: AsyncWrite + Send + Unpin>(&self, writer: &mut W) -> Result<()>;
/// Serialize this instance into a vector of bytes.
async fn try_to_vec(&self) -> Result<Vec<u8>> {
let mut result = Vec::with_capacity(DEFAULT_SERIALIZER_CAPACITY);
self.serialize(&mut result).await?;
Ok(result)
}
#[inline]
#[doc(hidden)]
fn u8_slice(slice: &[Self]) -> Option<&[u8]>
where
Self: Sized,
{
let _ = slice;
None
}
}
#[async_trait::async_trait]
impl BorshSerialize for u8 {
#[inline]
async fn serialize<W: AsyncWrite + Send + Unpin>(&self, writer: &mut W) -> Result<()> {
writer.write_all(core::slice::from_ref(self)).await
}
#[inline]
fn u8_slice(slice: &[Self]) -> Option<&[u8]> {
Some(slice)
}
} |
|
I was also thinking about introducing a separate trait for async methods and keep it under a feature-flag. This way it is not going to be a breaking change. @iho It is a nice-to-have, and we currently don't have an urgency for it, so let's wait for @hamidrezakp to experiment with it. Just for context, there is an issue in serde where reader methods are much slower than |
Sure, i will continue writing the whole thing and see if it works and benchmark it.
Good point, that's why we always support both reading from a |
for reference, I'm following this method that Jon mentioned here |
@hamidrezakp I assigned this issue to you for now as I am on-boarding new contributors and I don't want them to work on this issue now. I don't expect you to deliver the PR, I just want to indicate that it is "taken" for now (let's say, 1 month). If someone in the future (1+ months from now) finds this issue, and wants to address it, feel free to reignite the conversation. |
I have made a basic working version with derive macros 😄 . |
Hi, I was wondering that if there is any plan for adding Async support to (de)serializer?
The text was updated successfully, but these errors were encountered: