Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Question about const generics #330

Closed
chipsenkbeil opened this issue Jun 27, 2021 · 0 comments
Closed

Question about const generics #330

chipsenkbeil opened this issue Jun 27, 2021 · 0 comments

Comments

@chipsenkbeil
Copy link

I've seen some examples of using serde_as for explicitly-defined size ranges, but I'm struggling to figure out how to apply to const generics, if it's even possible.

use serde::{Serialize, Deserialize};
use serde_with::serde_as;

#[serde_as]
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
struct FixedMatrix<T, const ROW: usize, const COL: usize> {
    serde_as(as = "[[_; ROW]; COL]")
    data: [[T; ROW]; COL],
}

Was browsing through serde-rs/serde#1937 and saw mention of:

#[serde_with::serde_as]
#[derive(Serialize)]
struct Foo {
    #[serde_as(as = "[_; 2]")]
    bar: [String; 2],
    #[serde_as(as = "Vec<[_; 5]>")]
    foobar: Vec<[u8; 5]>,
}
@jonasbb jonasbb closed this as completed Jun 27, 2021
Repository owner locked and limited conversation to collaborators Jun 27, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants