-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bump in struct #111
Comments
In order to borrow multiple fields at once you can use the generated pub fn symbol_new(&mut self, bs: &S) -> Symbol {
let found = self.borrow_positions().get(bs).cloned();
if let Some(position) = found {
position
} else {
// If BS is new, add it to the list and update the position
let position = self.borrow_symbols().len() as Symbol;
self.with_mut(|fields| {
let b = fields.bumpalo.alloc_slice_clone(bs);
fields.positions.insert(b, position);
fields.symbols.push(b);
});
position
}
} (The error isn't specific to |
In fact the code I have had RefCell<Vec..> but will try this way. When using RefCell fields.symbols.borrow().len() fails because it cannot derive the type. Rust is like entangled Quantum Computing. If you change one thing it fails somewhere else. |
symbol_new is called millions of times in my application. Is there a way to 'borrow_mut' all once only such as returning them as struct and add new_symbol like to that ? Or is the only way |
I have this case:
I want to allocate binary strings with bumpalo and add them to a vec and hashmap to create a symbols table.
[u8] -> u32, u32 -> [u8].
Now the problem is that borrowing the bumpalo disallows adding to vec and hashmap ?
When putting symbols and positions into RefCell it feels like compiling, until fixing all errors then doesn't live long enough happens on #[self_referencing] line.
Not sure this is a bug. Is there a simple workaround I don't see ?
The text was updated successfully, but these errors were encountered: