27 Dec 2023 |
snover | rgnb: which thing are you trying to make an enum? | 05:17:07 |
rgnb | Child, and the case should be picked based on the string | 06:40:04 |
rgnb | and data would be the associated values ideally | 06:40:14 |
jam1garner | do you need to store the underlying string after? | 06:58:17 |
rgnb | no | 06:59:54 |
jam1garner | because if not, you can effectively do...
// field in Parent
#[br(count = child_count)]
children: Vec<ChildEnum>,
#[br(try_map = ChildEnum::from_child)]
enum ChildEnum {
// TODO
}
impl ChildEnum {
fn from_child(child: Child) -> Result<Self, Whatever> {
// exercise for the reader
}
}
struct Child {
name_index: u16,
length: u16,
#[br(count = length)]
data: Vec<u8>
} | 07:01:16 |
jam1garner | basically "top-level try_map on the ChildEnum" | 07:01:30 |
jam1garner | * basically "top-level try_map on the ChildEnum enum" | 07:01:37 |
jam1garner | * basically "top-level try_map on the ChildEnum enum" is the magic sauce | 07:01:43 |
rgnb | hmm, but how would I add associated values? | 08:49:37 |
jam1garner | that's not really a feature the type system has? | 08:54:58 |
jam1garner | associated consts are properties of types, and enum variants aren't types | 08:55:18 |
jam1garner | unless you mean like uhhhh | 08:55:39 |
jam1garner | parsing additional data based on the string? | 08:55:50 |
jam1garner | if that's the case I'd store the string as a br(temp) value then use br(args) + br(import) on the enum | 08:56:44 |
jam1garner | You'd use pre_assert on the enum variants https://docs.rs/binrw/latest/binrw/docs/attribute/index.html#pre-assert | 08:57:48 |
jam1garner | Not the most elegant but neither is the file format you're describing | 08:58:02 |
rgnb | my bad, I meant enum fields - associated values is what they are called in Swift | 08:58:10 |
jam1garner | understandable | 08:58:23 |
jam1garner | I certainly didn't help given I initially just missed that half of the question | 08:58:52 |
rgnb | I appreciate the effort anyway :) | 09:00:21 |
un3afe | Man I wish serde had support for const generic for array size... I mean who the hell really use [T; 0] 😕 | 20:46:17 |
28 Dec 2023 |
un3afe | Could you say what is the use case for you? | 08:40:59 |
jam1garner | () isn't type safe enough | 08:42:21 |
un3afe | I think when we finally get specialization this won't be a problem anymore 🫠 | 08:43:06 |
29 Dec 2023 |
kekronbekron | yoooooooooo | 02:23:35 |
kekronbekron | Will this be useful to binrw - pointer offset API - https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html#pointer-byte-offset-apis | 02:23:52 |
octylfractal | binrw doesn't do anything with pointers, so i doubt it | 02:25:24 |
kekronbekron | hmm.. was wondering if it can help in uses of stream_position | 02:28:48 |
kekronbekron | like the pos jumping I was on about some months ago | 02:29:00 |