Skip to content

Do we really need CowMut Enum? #195

Open

Description

@page0egap

CowMut enum is in file cow_mut.rs and is mainly used by GreenNodeBuilder to deal with the differences of owning NodeCache or mutable reference of NodeCache. I wonder whether using trait BorrowMut is better? As trait has no runtime overhead than enum?

Activity

  1. bjorn3 commented on May 31, 2025

    @bjorn3

    GreenNodeBuilder starts with a borrowed CowMut and may or may not replace it with an owned CowMut in the future. Using BorrowMut doesn't work for this as you have to commit to either a borrowed or owned value in advance.

  2. page0egap commented on May 31, 2025

    @page0egap
    Author

    GreenNodeBuilder starts with a borrowed CowMut and may or may not replace it with an owned CowMut in the future. Using BorrowMut doesn't work for this as you have to commit to either a borrowed or owned value in advance.

    What's the meaning of "borrowed" or "owned"? Is it state of the CowMut enum?

    I'm not very sure. But I did not find any state changes in CowMut and the usage in GreenNodeBuilder. It seems like that the lifetime and the state of CowMut(cache) is stabelized when GreenNodeBuilder was first created.

  3. page0egap commented on May 31, 2025

    @page0egap
    Author

    And I think even replace CowMut with BorrowMut does not change the future plan of "GreenNodeBuilder starts with a borrowed CowMut and may or may not replace it with an owned CowMut". As the change of the state of cache(CowMut) would reflect on the lifetime of GreenNodeBuilder?

    Finally, thanks for explaining the considerations of the design. I just find it hard to capture the design of the CowMut.

  4. bjorn3 commented on May 31, 2025

    @bjorn3

    I'm not very sure. But I did not find any state changes in CowMut and the usage in GreenNodeBuilder. It seems like that the lifetime and the state of CowMut(cache) is stabelized when GreenNodeBuilder was first created.

    Looks like that is indeed the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions