Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable IntoNotification::tag with no_std #81

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading