FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

compiler-core: implement DerefMut and IndexMut for Constants by youknowone · Pull Request #8557 · RustPython/RustPython · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rs  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 13 additions & 1 deletion crates/compiler-core/src/bytecode.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bitflags::bitflags;
use core::{
cell::UnsafeCell,
hash, mem,
ops::{Deref, Index, IndexMut},
ops::{Deref, DerefMut, Index, IndexMut},
sync::atomic::{AtomicU8, AtomicU16, AtomicUsize, Ordering},
};
use itertools::Itertools;
Expand Down Expand Up @@ -383,6 +383,12 @@ impl<C: Constant> Deref for Constants<C> {
}
}

impl<C: Constant> DerefMut for Constants<C> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl<C: Constant> Index<oparg::ConstIdx> for Constants<C> {
type Output = C;

Expand All @@ -391,6 +397,12 @@ impl<C: Constant> Index<oparg::ConstIdx> for Constants<C> {
}
}

impl<C: Constant> IndexMut<oparg::ConstIdx> for Constants<C> {
fn index_mut(&mut self, consti: oparg::ConstIdx) -> &mut Self::Output {
&mut self.0[consti.as_usize()]
}
}

impl<C: Constant> FromIterator<C> for Constants<C> {
fn from_iter<T: IntoIterator<Item = C>>(iter: T) -> Self {
Self(iter.into_iter().collect())
Expand Down
Loading

Back | FazBrowse Home | New Git URL