Skip to content

Commit

Permalink
Implement Clone and Copy for InterchangeRef
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-nitrokey committed Jan 14, 2025
1 parent 78306b4 commit a82570f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
### Added

- Add `Clone` and `Copy` implementations for `InterchangeRef`.

## [0.3.1][] - 2024-06-20

Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ pub struct InterchangeRef<'alloc, Rq, Rp> {
channels: &'alloc [Channel<Rq, Rp>],
last_claimed: &'alloc AtomicUsize,
}

impl<'alloc, Rq, Rp> InterchangeRef<'alloc, Rq, Rp> {
/// Claim one of the channels of the interchange. Returns None if called more than `N` times.
pub fn claim(&self) -> Option<(Requester<'alloc, Rq, Rp>, Responder<'alloc, Rq, Rp>)> {
Expand All @@ -958,6 +959,17 @@ impl<'alloc, Rq, Rp> InterchangeRef<'alloc, Rq, Rp> {
}
}

impl<Rq, Rp> Clone for InterchangeRef<'_, Rq, Rp> {
fn clone(&self) -> Self {
Self {
channels: self.channels,
last_claimed: self.last_claimed,
}
}
}

impl<Rq, Rp> Copy for InterchangeRef<'_, Rq, Rp> {}

#[cfg(not(loom))]
impl<Rq, Rp, const N: usize> Default for Interchange<Rq, Rp, N> {
fn default() -> Self {
Expand Down

0 comments on commit a82570f

Please sign in to comment.