Skip to content

Implement MappedMutexGuard #59

Closed

Activity

  1. added
    enhancement
    help wanted
    good first issue
    on Jul 19, 2025
  2. orthur2 commented on Jul 19, 2025

    @orthur2
    Contributor

    Hey , tisonkun, I saw your post on X which led me to this repository. After some time thinking about this issue, I'd be very interested in tackling it. Could you please assign it to me?

    I've just been digging into the problem. I wasn't familiar with MappedMutexGuard before, but after reading through the documentation and materials you provided, I believe I have a general understanding of the concept.
    Here's my current understanding: when you lock a Mutex<MyStruct>, you get a MutexGuard<MyStruct> which provides access to the entire MyStruct. However, sometimes you only need to access a single field, like MyStruct.field. MappedMutexGuard is designed for this exact scenario. It allows one to map(or try map which for a Option field) a MutexGuard<MyStruct> into a MappedMutexGuard<FieldType>, which points only to MyStruct.field.
    So MappedMutexGuard can provide a safe and convenient way to lock and access only a portion of the data when the Mutex protects a complex struct or enum.
    Could you let me know if my understanding is on the right track? I'm very open to any corrections and would appreciate the feedback.

    My initial idea for implementing this issue is that I will take a detailed look at the existing mutex and rwlock modules in the project, and then refer to the example in #58, I plan to implement six different MappedMutexGuards gradually through the combination of Ownership and Lock Type:

    • MappedMutexGuard (NonOwned, Mutex)
    • OwnedMappedMutexGuard (Owned, Mutex)
    • MappedRwLockReadGuard (NonOwned, RWLockRead)
    • OwnedMappedRwLockReadGuard (Owned, RWLockRead)
    • MappedRwLockWriteGuard (NonOwned, RWLockWrite)
    • OwnedMappedRwLockWriteGuard (Owned, RWLockWrite)

    To be honest, I should also mention that while I have studied Rust and have some hands-on experience with it, I haven't worked on a large project in Rust before, so I might be a bit "rusty". However, I'm a fast learner and highly motivated to contribute.

    Looking forward to hearing from you!

  3. tisonkun commented on Jul 19, 2025

    @tisonkun
    MemberAuthor

    @orthur2 Your understanding is correct. Go forward to prepare a patch for review :D

  4. tisonkun commented on Jul 26, 2025

    @tisonkun
    MemberAuthor

    I may resume this task in days.

    @orthur2 are you working on this issue? If so, you can submit a draft and firstly take part of the structs above done - no need to get everything done in one turn.

  5. orthur2 commented on Jul 26, 2025

    @orthur2
    Contributor

    @tisonkun ,

    Yes, I'm on it. So far, I've finished the MappedMutexGuard and OwnedMappedMutexGuard in the mutex module and am now working on the remaining parts and adding tests.

    My apologies for the slow progress. I had something on last Sunday and could only spend time after work during the week to get familiar with the project.

    As you suggested, I can open a draft PR with the current progress first, and then I will push the rest of the changes. I expect to complete the remaining parts this weekend.

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

    enhancementgood first issuehelp wanted

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions