From ef190f2d66af2a7207a5dd85d067ad75f1933827 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 21 Apr 2024 22:32:47 -0500 Subject: [PATCH] cl-structures: Add `get_many_mut` implementation for Pool (currently delegates to unstable std) --- compiler/cl-structures/src/intern_pool.rs | 8 ++++++++ compiler/cl-structures/src/lib.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/cl-structures/src/intern_pool.rs b/compiler/cl-structures/src/intern_pool.rs index deffced..654ab94 100644 --- a/compiler/cl-structures/src/intern_pool.rs +++ b/compiler/cl-structures/src/intern_pool.rs @@ -53,6 +53,7 @@ macro_rules! make_intern_key {($($(#[$meta:meta])* $name:ident),*$(,)?) => {$( } } )*}} +use core::slice::GetManyMutError; use std::ops::{Index, IndexMut}; pub use make_intern_key; @@ -91,6 +92,13 @@ impl Pool { self.pool.get_mut(index.get()) } + pub fn get_many_mut( + &mut self, + indices: [ID; N], + ) -> Result<[&mut T; N], GetManyMutError> { + self.pool.get_many_mut(indices.map(|id| id.get())) + } + pub fn iter(&self) -> impl Iterator { self.pool.iter() } diff --git a/compiler/cl-structures/src/lib.rs b/compiler/cl-structures/src/lib.rs index a986cf1..b0728a4 100644 --- a/compiler/cl-structures/src/lib.rs +++ b/compiler/cl-structures/src/lib.rs @@ -2,7 +2,7 @@ //! - [Span](struct@span::Span): Stores a start and end [Loc](struct@span::Loc) //! - [Loc](struct@span::Loc): Stores the index in a stream #![warn(clippy::all)] -#![feature(inline_const, dropck_eyepatch, decl_macro)] +#![feature(inline_const, dropck_eyepatch, decl_macro, get_many_mut)] #![deny(unsafe_op_in_unsafe_fn)] pub mod span;