Skip to content
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

FR: Provide a way to borrow data from a slice. #122

Closed
mina86 opened this issue Jan 25, 2023 · 4 comments
Closed

FR: Provide a way to borrow data from a slice. #122

mina86 opened this issue Jan 25, 2023 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@mina86
Copy link
Contributor

mina86 commented Jan 25, 2023

For example,

let serialised: &[u8] = todo!();
let slice = <&[u8]>::try_from_slice(serialised)?;
#[derive(BorshDeserialise)]
enum Record<'a> {
    JustKey(&'a [u8]),
    KeyAndValue(&'a [u8], &'a [u8]),
}

match Record::try_from_slice(serialised) {
    Record::JustKey(key) => todo!(),
    Record::KeyAndValue(key, value) => todo!(),
}
@frol frol added enhancement New feature or request help wanted Extra attention is needed labels Jan 27, 2023
@frol
Copy link
Collaborator

frol commented Jan 27, 2023

This is definitely a great feature to have! Yet, I believe it is not going to be on Pagoda's plate any time soon, but I am happy to review a PR if someone will implement this feature.

@dj8yfo
Copy link
Collaborator

dj8yfo commented Jun 23, 2023

this is a minimal example of a variant of how this could be done. https://github.com/dj8yfo/borrow_deserialize
It's not minimal enough to fit into a small gist.

It might be better to create a separate trait BorshBorrowDeserialize<'de> for this and not attempt to mix everything in one trait
https://github.com/dj8yfo/borrow_deserialize/blob/master/src/deserialize_trait.rs#L7

@frol
Copy link
Collaborator

frol commented Jun 26, 2023

Well, adding a method and a lifetime to the existing public trait is going to be a major breaking change. I don't have the capacity right now to assess how cumbersome would a separate trait path be. I think overall, we may keep this issue in a backlog for now and think about it in the background while we are addressing other papercuts.

@frol
Copy link
Collaborator

frol commented Jun 29, 2023

Closing this in favor of #90

@frol frol closed this as completed Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants