4 ms·
Not as things stand now. For this functionality you would want something closer to `I32<0..500>` and `struct I32<const RANGE: Range>(i32)`, so then operations b
by estebank 5y ago
Not as things stand now. For this functionality you would want something closer to `I32<0..500>` and `struct I32<const RANGE: Range>(i32)`, so then operations between two `I32<RANGE>` can check what each corresponding const param is. I don't know if this will be possible in the short term, but I know that quite a few people want something along these lines, so I think it might happen at some point.
- ww520 5y agoYes, that would be ideal. Was just thinking whether the const generics can be hacked to do the same thing.
- estebank 5y agoYou can't use field access today, so having a const param `struct Range<T> { start: T, end: T }` isn't yet useful, but you can still get something working, although the error message is terrible: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c77cd060bcfa4e95c439e9d48996542a https://play.rust-lang.org/?version=nightly&mode=debug&editi... Edit: I'm honestly surprised at how usable this is already in the current state of nightly: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=f60ab9c71a5c91f709e82c13f9cf851a https://play.rust-lang.org/?version=nightly&mode=debug&editi...
- ww520 5y agoExcellent hack! This demonstrates it actually works. Just need to make it ergonomic for everyday work. That's awesome.