I have a trait that look like this:
pub trait Buf<const N: usize> {
fn to_buf(&self) -> [u8; N];
fn from_buf(buf: [u8; N]) -> Self;
}
However I want to do something like this:
trait Buf {
const N: usize;
fn to_buf(&self) -> [u8; Self::N];
fn from_buf(buf: [u8; Self::N]) -> Self;
}
It give me this error (playground):
|
| fn to_buf(&self) -> [u8; Self::N];
| ^^^^^^^ cannot perform const operation using `Self`
|
= note: type parameters may not be used in const expressions
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
Is it possible?