Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Implement Encodable/Decodable traits for [T; 32+] #158

Closed
noiseless opened this issue Jul 26, 2016 · 3 comments
Closed

Implement Encodable/Decodable traits for [T; 32+] #158

noiseless opened this issue Jul 26, 2016 · 3 comments

Comments

@noiseless
Copy link

As I can see it is possible to simply implement this by adding needed numbers to

array! {
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16,
15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
}

(https://github.com/rust-lang-nursery/rustc-serialize/blob/master/src/serialize.rs#L1306)

What caused the current number of implementations?

I want to serialize [u8, 64], now for this I need to create my own type and to write implementation for it, there is no way to create trait implementation for non-foreing type (rust-lang/rfcs#1023).

@bluss
Copy link
Contributor

bluss commented Nov 10, 2016

The number is of course arbitrary, but libstd itself is using 0–32 inclusive as well. Past that range, arrays don't impl PartialEq or AsRef etc, a range of traits. So there's a certain consistency.

@dtolnay
Copy link
Contributor

dtolnay commented Feb 2, 2017

In Serde we plan to support this by generating smarter code rather than by extending the array impls to bigger sizes. serde-rs/serde#631

#[derive(Serialize)]
struct S {
    array: [u8; 64],
}

Here the generated code should see that the array is bigger than our biggest array impl so it should generate a loop to serialize the array rather than trying to delegate to [u8; 64]'s implementation of Serialize (which doesn't exist).

@alexcrichton
Copy link
Contributor

I'm going to close this now that this crate is deprecated in favor of serde. We're discontinuing feature development in rustc-serialize but will still continue to merge bug fixes if they arise.

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

No branches or pull requests

4 participants