Skip to content

Commit cb2a88b

Browse files
committed
Implement Send+Sync for VarLenAscii/Unicode/Array
1 parent 1dff575 commit cb2a88b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

hdf5-types/src/array.rs

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

145+
// Safety: `VarLenArray` allocates and frees memory for its data, which is copied
146+
// from its original location; it never holds a reference to the data used to create it.
147+
// Therefore if `T` is Send, so is `VarLenArray<T>`
148+
unsafe impl<T: Copy + Send> Send for VarLenArray<T> {}
149+
// Safety: No interior mutability or potential for data races if `T` is `Sync`.
150+
unsafe impl<T: Copy + Sync> Sync for VarLenArray<T> {}
151+
145152
#[cfg(test)]
146153
pub mod tests {
147154
use super::VarLenArray;

hdf5-types/src/string.rs

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

285+
// Safety: `VarLenAscii` allocates and frees memory for its data, which is copied
286+
// from its original location; it never holds a reference to the data used to create it.
287+
unsafe impl Send for VarLenAscii {}
288+
// Safety: No interior mutability or potential for data races.
289+
unsafe impl Sync for VarLenAscii {}
290+
285291
// ================================================================================
286292

287293
#[repr(C)]
@@ -371,6 +377,12 @@ impl FromStr for VarLenUnicode {
371377
}
372378
}
373379

380+
// Safety: `VarLenUnicode` allocates and frees memory for its data, which is copied
381+
// from its original location; it never holds a reference to the data used to create it.
382+
unsafe impl Send for VarLenUnicode {}
383+
// Safety: No interior mutability or potential for data races.
384+
unsafe impl Sync for VarLenUnicode {}
385+
374386
// ================================================================================
375387

376388
#[repr(C)]

0 commit comments

Comments
 (0)