Skip to content

Commit

Permalink
Disable IntoNotification::tag with no_std (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 10, 2023
1 parent 4965ddd commit 450942e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/notify.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! The `Notification` trait for specifying notification.

use crate::sync::atomic::{self, Ordering};
#[cfg(feature = "std")]
use core::fmt;

pub(crate) use __private::Internal;
Expand Down Expand Up @@ -155,13 +156,15 @@ where
}

/// Use a tag to notify listeners.
#[cfg(feature = "std")]
#[derive(Debug, Clone)]
#[doc(hidden)]
pub struct Tag<N: ?Sized, T> {
tag: T,
inner: N,
}

#[cfg(feature = "std")]
impl<N: ?Sized, T> Tag<N, T> {
/// Create a new `Tag` with the given tag and notification.
fn new(tag: T, inner: N) -> Self
Expand All @@ -172,6 +175,7 @@ impl<N: ?Sized, T> Tag<N, T> {
}
}

#[cfg(feature = "std")]
impl<N, T> NotificationPrivate for Tag<N, T>
where
N: Notification + ?Sized,
Expand All @@ -197,12 +201,14 @@ where
}

/// Use a function to generate a tag to notify listeners.
#[cfg(feature = "std")]
#[doc(hidden)]
pub struct TagWith<N: ?Sized, F> {
tag: F,
inner: N,
}

#[cfg(feature = "std")]
impl<N: fmt::Debug, F> fmt::Debug for TagWith<N, F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
struct Ellipses;
Expand All @@ -220,14 +226,15 @@ impl<N: fmt::Debug, F> fmt::Debug for TagWith<N, F> {
}
}

#[cfg(feature = "std")]
impl<N, F> TagWith<N, F> {
/// Create a new `TagFn` with the given tag function and notification.
#[cfg(feature = "std")]
fn new(tag: F, inner: N) -> Self {
Self { tag, inner }
}
}

#[cfg(feature = "std")]
impl<N, F, T> NotificationPrivate for TagWith<N, F>
where
N: Notification + ?Sized,
Expand Down Expand Up @@ -466,6 +473,9 @@ pub trait IntoNotification: __private::Sealed {
/// The tag provided is cloned to provide the tag for all listeners. In cases where this is not flexible
/// enough, use [`IntoNotification::with_tag()`] instead.
///
/// Tagging functions cannot be implemented efficiently for `no_std`, so this is only available
/// when the `std` feature is enabled.
///
/// # Examples
///
/// ```
Expand All @@ -483,6 +493,7 @@ pub trait IntoNotification: __private::Sealed {
/// assert_eq!(listener1.as_mut().wait(), true);
/// assert_eq!(listener2.as_mut().wait(), false);
/// ```
#[cfg(feature = "std")]
fn tag<T: Clone>(self, tag: T) -> Tag<Self::Notify, T>
where
Self: Sized + IntoNotification<Tag = ()>,
Expand Down

0 comments on commit 450942e

Please sign in to comment.