Skip to content

Commit 556b43d

Browse files
authored
Merge pull request #270 from watsaig/impl-send-sync
Implement Send+Sync for VarLenAscii/Unicode/Array
2 parents 1dff575 + 1455a77 commit 556b43d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

hdf5-types/src/array.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ impl<T: Copy + fmt::Debug> fmt::Debug for VarLenArray<T> {
142142
}
143143
}
144144

145+
// Safety: Memory backed by `VarLenArray` can be accessed and freed from any thread
146+
unsafe impl<T: Copy + Send> Send for VarLenArray<T> {}
147+
// Safety: `VarLenArray` has no interior mutability
148+
unsafe impl<T: Copy + Sync> Sync for VarLenArray<T> {}
149+
145150
#[cfg(test)]
146151
pub mod tests {
147152
use super::VarLenArray;

hdf5-types/src/string.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ impl AsAsciiStr for VarLenAscii {
282282
}
283283
}
284284

285+
// Safety: Memory backed by `VarLenAscii` can be accessed and freed from any thread
286+
unsafe impl Send for VarLenAscii {}
287+
// Safety: `VarLenAscii` has no interior mutability
288+
unsafe impl Sync for VarLenAscii {}
289+
285290
// ================================================================================
286291

287292
#[repr(C)]
@@ -371,6 +376,11 @@ impl FromStr for VarLenUnicode {
371376
}
372377
}
373378

379+
// Safety: Memory backed by `VarLenUnicode` can be accessed and freed from any thread
380+
unsafe impl Send for VarLenUnicode {}
381+
// Safety: `VarLenUnicode` has no interior mutability
382+
unsafe impl Sync for VarLenUnicode {}
383+
374384
// ================================================================================
375385

376386
#[repr(C)]

0 commit comments

Comments
 (0)