Code Monkey home page Code Monkey logo

Comments (4)

nook1208 avatar nook1208 commented on August 21, 2024 1

When I searched, there is no way to define immutable field in struct.
I think that adding private realm_id and ipa_bits field in Rec and making only init() and getter function is the best like the following comment in this reference

The best, as Lily Ballard noted, is that you can declare your Shape field as private and make a getter method using impl A {...}.

let me make a PR for it :)

from islet.

jinbpark avatar jinbpark commented on August 21, 2024 1

Please let me know if you are already implementing it :)

Nothing done yet. Appreciate it if you bring up this issue and make a draft PR! I'll happily get involved with that PR after that draft.

from islet.

jinbpark avatar jinbpark commented on August 21, 2024

Rec and making only init() and getter function --> I agree this is good enough.

My initial thought on how to implement this is as follows.

// define accessor
impl<'a, E> EntryGuard<'a, E> {
    // new function for child-parent access
    // NOTE:  ==> add a comment here about the two rules for child-parent access
    pub fn parent_content<T: Content>(&self) -> &T {
       // E:  the type of child (e.g., Rec),   T: the type of parent (e.g., Rd)
       // <TODO>  do type checking--> it looks like, either (1) or (2). ==> this is for Rule-1.
       //     (1) if E::type == Rec && T::type == Rd,  error otherwise  
       //     (2) if E::type::get_parent_type() == T::type,  error otherwise
       unsafe { &*(self.addr as *const T) }
    }

   // do not make parent_content_mut() as it violates Rule-2.  ==> this is for Rule-2.
   // pub fn parent_content_mut<T: Content>(&mut self) -> &mut T {
}

// how to use it
let mut rec_granule = get_granule_if!(arg[0], GranuleState::Rec)?;
let mut rec = rec_granule.content_mut::<Rec>();
let rd = rec_granule.parent_content::<Rd>();
// accessing Rd (parent) still requires the lock of Rec (child) but not require the lock of Rd (parent).
// in this way, it's guaranteed Rd (parent) is alive as it's guaranteed Rd never gets destroyed because of rec-granule-lock.
...
rd.id();
rd.ipa_bits();

from islet.

nook1208 avatar nook1208 commented on August 21, 2024

I see. thank you for the code. if we have to read other fields of parent a lot besides realm_id, ipa_bits, then that's a good approach.
Please let me know if you are already implementing it :)

from islet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.