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

Implement support for Box<[T]> and Arc<[T]> #633

Open
nazar-pc opened this issue Oct 13, 2024 · 3 comments
Open

Implement support for Box<[T]> and Arc<[T]> #633

nazar-pc opened this issue Oct 13, 2024 · 3 comments

Comments

@nazar-pc
Copy link
Contributor

Arc<[T]> is especially helpful in cases where something needs to be sent into a different thread, but cloning and double indirection are undesirable.

Right now both fail something like this:

error[E0277]: the trait bound `[subspace_core_primitives::pieces::PieceIndex]: parity_scale_codec::WrapperTypeDecode` is not satisfied
  --> crates/subspace-networking/src/protocols/request_response/handlers/cached_piece_by_index.rs:28:24
   |
28 |     pub cached_pieces: Box<[PieceIndex]>,
   |                        ^^^^^^^^^^^^^^^^^ the trait `parity_scale_codec::WrapperTypeDecode` is not implemented for `[subspace_core_primitives::pieces::PieceIndex]`, which is required by `std::boxed::Box<[subspace_core_primitives::pieces::PieceIndex]>: parity_scale_codec::Decode`
   |
   = help: the following other types implement trait `parity_scale_codec::WrapperTypeDecode`:
             std::boxed::Box<T>
             std::rc::Rc<T>
             std::sync::Arc<T>
   = note: required for `[subspace_core_primitives::pieces::PieceIndex]` to implement `parity_scale_codec::Decode`
   = note: 1 redundant requirement hidden
   = note: required for `std::boxed::Box<[subspace_core_primitives::pieces::PieceIndex]>` to implement `parity_scale_codec::Decode`

I'm not 100% sure, but suspect it is an upstream issue since downstream users will not be able to implement WrapperTypeDecode for Box<[T]> or Arc<[T]>.

@teor2345
Copy link

teor2345 commented Oct 13, 2024

Specifically, this will need an implementation of WrapperTypeDecode<Wrapped = Vec<T>> for these types, because Wrapped has to be Into<Arc<[T]>>. Since slices are unsized, they can’t implement Into.

We might as well also do Rc<[T]>.

@chanderprakash20
Copy link

Hi @nazar-pc is your issue get resolved or not ?

@teor2345
Copy link

I can’t see any new PRs in the last few weeks that implement this feature. Is there something specific that you did that you think will resolve this issue?

This PR is implements the Box part of this feature, but hasn’t been reviewed or merged recently:
#565

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants