On Mon, 2025-11-17 at 18:10 -0500, Joel Fernandes wrote:
> // Usage example - no more match statements needed!
> impl FalconLoadParams for FwsecFirmware {
>     fn dmem_load_params(&self) -> FalconLoadTarget {
>         FalconLoadTarget {
>             src_start: 0,
>             dst_start: 0,
>             len: self.desc.dmem_load_size(),
>         }
>     }
> }

This doesn't work because the current code:

    fn dmem_load_params(&self) -> FalconLoadTarget {
        match &self.desc {
            FalconUCodeDesc::V2(v2) => FalconLoadTarget {
                src_start: v2.dmem_offset,
                dst_start: v2.dmem_phys_base,
                len: v2.dmem_load_size,
            },
            FalconUCodeDesc::V3(v3) => FalconLoadTarget {
                src_start: v3.imem_load_size,
                dst_start: v3.dmem_phys_base,
                len: v3.dmem_load_size,
            }
        }
    }

uses different values for src_start and dst_start depending on whether it's v2 
or v3.

I've implemented the trait object, but I don't think the end result is an 
improvement.  Sure, I've
replaced 9 match statements with 1, but I had to create the trait object and 
two more
implementations.  So I've deleted 37 lines, but I had to add 54.

I will post the trait object change as its own RFC patch, so you can see for 
yourself.  My
preference would be to drop it, however.  As far as I'm concerned, this is yet 
another example of
making the Rust code more convoluted just because it's a "neat feature" of the 
language.

Reply via email to