Skip to content

Commit

Permalink
Make Label Send + Sync (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus authored May 10, 2023
1 parent 140f19e commit a73e63b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions buffer/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,14 @@ mod alloc_support {
use sval::Stream as _;
use sval_derive::*;

#[test]
fn is_send_sync() {
fn assert<T: Send + Sync>() {}

assert::<ValueBuf>();
assert::<Value>();
}

#[test]
fn empty_is_complete() {
assert!(!ValueBuf::new().is_complete());
Expand Down
12 changes: 12 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ pub struct Label<'computed> {
_marker: PhantomData<&'computed str>,
}

// SAFETY: Label doesn't mutate or synchronize: it acts just like a `&str`
unsafe impl<'computed> Send for Label<'computed> { }
// SAFETY: Label doesn't mutate or synchronize: it acts just like a `&str`
unsafe impl<'computed> Sync for Label<'computed> { }

#[cfg(not(feature = "alloc"))]
impl<'computed> Clone for Label<'computed> {
fn clone(&self) -> Self {
Expand Down Expand Up @@ -344,6 +349,13 @@ mod alloc_support {
mod tests {
use super::*;

#[test]
fn label_send_sync() {
fn assert<T: Send + Sync>() {}

assert::<Label>();
}

#[test]
fn label_static() {
let label = Label::new("a");
Expand Down

0 comments on commit a73e63b

Please sign in to comment.