!homDUJhmxHaZNgyLVA:matrix.org

binrw

165 Members
Official Matrix channel for the binread & binrw Rust libraries. Bridged to Discord. https://github.com/jam1garner/binrw/12 Servers

Load older messages


SenderMessageTime
27 Dec 2023
@snover:matrix.orgsnover rgnb: which thing are you trying to make an enum? 05:17:07
@rgnb:matrix.orgrgnb Child, and the case should be picked based on the string  06:40:04
@rgnb:matrix.orgrgnb and data would be the associated values ideally  06:40:14
@_discord_63814827654516736:t2bot.iojam1garner do you need to store the underlying string after? 06:58:17
@rgnb:matrix.orgrgnb no 06:59:54
@_discord_63814827654516736:t2bot.iojam1garner 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
@_discord_63814827654516736:t2bot.iojam1garner basically "top-level try_map on the ChildEnum" 07:01:30
@_discord_63814827654516736:t2bot.iojam1garner * basically "top-level try_map on the ChildEnum enum" 07:01:37
@_discord_63814827654516736:t2bot.iojam1garner * basically "top-level try_map on the ChildEnum enum" is the magic sauce 07:01:43
@rgnb:matrix.orgrgnb hmm, but how would I add associated values? 08:49:37
@_discord_63814827654516736:t2bot.iojam1garner that's not really a feature the type system has? 08:54:58
@_discord_63814827654516736:t2bot.iojam1garner associated consts are properties of types, and enum variants aren't types 08:55:18
@_discord_63814827654516736:t2bot.iojam1garner unless you mean like uhhhh 08:55:39
@_discord_63814827654516736:t2bot.iojam1garner parsing additional data based on the string? 08:55:50
@_discord_63814827654516736:t2bot.iojam1garner 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
@_discord_63814827654516736:t2bot.iojam1garner You'd use pre_assert on the enum variants https://docs.rs/binrw/latest/binrw/docs/attribute/index.html#pre-assert 08:57:48
@_discord_63814827654516736:t2bot.iojam1garner Not the most elegant but neither is the file format you're describing 08:58:02
@rgnb:matrix.orgrgnb my bad, I meant enum fields - associated values is what they are called in Swift  08:58:10
@_discord_63814827654516736:t2bot.iojam1garner understandable 08:58:23
@_discord_63814827654516736:t2bot.iojam1garner I certainly didn't help given I initially just missed that half of the question 08:58:52
@rgnb:matrix.orgrgnb I appreciate the effort anyway :) 09:00:21
@_discord_792157891065937931:t2bot.ioun3afe 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
@_discord_792157891065937931:t2bot.ioun3afe Could you say what is the use case for you? 08:40:59
@_discord_63814827654516736:t2bot.iojam1garner () isn't type safe enough 08:42:21
@_discord_792157891065937931:t2bot.ioun3afe I think when we finally get specialization this won't be a problem anymore 🫠 08:43:06
29 Dec 2023
@_discord_1015217000777252985:t2bot.iokekronbekron yoooooooooo 02:23:35
@_discord_1015217000777252985:t2bot.iokekronbekron 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
@_discord_101805079555764224:t2bot.iooctylfractal binrw doesn't do anything with pointers, so i doubt it 02:25:24
@_discord_1015217000777252985:t2bot.iokekronbekron hmm.. was wondering if it can help in uses of stream_position 02:28:48
@_discord_1015217000777252985:t2bot.iokekronbekron like the pos jumping I was on about some months ago 02:29:00

Show newer messages


Back to Room ListRoom Version: 6