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

Apply unreachable_pub lint #637

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions crossbeam-channel/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ impl<T> SelectHandle for Receiver<T> {
}

/// Writes a message into the channel.
pub unsafe fn write<T>(s: &Sender<T>, token: &mut Token, msg: T) -> Result<(), T> {
pub(crate) unsafe fn write<T>(s: &Sender<T>, token: &mut Token, msg: T) -> Result<(), T> {
match &s.flavor {
SenderFlavor::Array(chan) => chan.write(token, msg),
SenderFlavor::List(chan) => chan.write(token, msg),
Expand All @@ -1494,7 +1494,7 @@ pub unsafe fn write<T>(s: &Sender<T>, token: &mut Token, msg: T) -> Result<(), T
}

/// Reads a message from the channel.
pub unsafe fn read<T>(r: &Receiver<T>, token: &mut Token) -> Result<T, ()> {
pub(crate) unsafe fn read<T>(r: &Receiver<T>, token: &mut Token) -> Result<T, ()> {
match &r.flavor {
ReceiverFlavor::Array(chan) => chan.read(token),
ReceiverFlavor::List(chan) => chan.read(token),
Expand Down
14 changes: 7 additions & 7 deletions crossbeam-channel/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Counter<C> {
}

/// Wraps a channel into the reference counter.
pub fn new<C>(chan: C) -> (Sender<C>, Receiver<C>) {
pub(crate) fn new<C>(chan: C) -> (Sender<C>, Receiver<C>) {
let counter = Box::into_raw(Box::new(Counter {
senders: AtomicUsize::new(1),
receivers: AtomicUsize::new(1),
Expand All @@ -34,7 +34,7 @@ pub fn new<C>(chan: C) -> (Sender<C>, Receiver<C>) {
}

/// The sending side.
pub struct Sender<C> {
pub(crate) struct Sender<C> {
counter: *mut Counter<C>,
}

Expand All @@ -45,7 +45,7 @@ impl<C> Sender<C> {
}

/// Acquires another sender reference.
pub fn acquire(&self) -> Sender<C> {
pub(crate) fn acquire(&self) -> Sender<C> {
let count = self.counter().senders.fetch_add(1, Ordering::Relaxed);

// Cloning senders and calling `mem::forget` on the clones could potentially overflow the
Expand All @@ -63,7 +63,7 @@ impl<C> Sender<C> {
/// Releases the sender reference.
///
/// Function `disconnect` will be called if this is the last sender reference.
pub unsafe fn release<F: FnOnce(&C) -> bool>(&self, disconnect: F) {
pub(crate) unsafe fn release<F: FnOnce(&C) -> bool>(&self, disconnect: F) {
if self.counter().senders.fetch_sub(1, Ordering::AcqRel) == 1 {
disconnect(&self.counter().chan);

Expand All @@ -89,7 +89,7 @@ impl<C> PartialEq for Sender<C> {
}

/// The receiving side.
pub struct Receiver<C> {
pub(crate) struct Receiver<C> {
counter: *mut Counter<C>,
}

Expand All @@ -100,7 +100,7 @@ impl<C> Receiver<C> {
}

/// Acquires another receiver reference.
pub fn acquire(&self) -> Receiver<C> {
pub(crate) fn acquire(&self) -> Receiver<C> {
let count = self.counter().receivers.fetch_add(1, Ordering::Relaxed);

// Cloning receivers and calling `mem::forget` on the clones could potentially overflow the
Expand All @@ -118,7 +118,7 @@ impl<C> Receiver<C> {
/// Releases the receiver reference.
///
/// Function `disconnect` will be called if this is the last receiver reference.
pub unsafe fn release<F: FnOnce(&C) -> bool>(&self, disconnect: F) {
pub(crate) unsafe fn release<F: FnOnce(&C) -> bool>(&self, disconnect: F) {
if self.counter().receivers.fetch_sub(1, Ordering::AcqRel) == 1 {
disconnect(&self.counter().chan);

Expand Down
40 changes: 22 additions & 18 deletions crossbeam-channel/src/flavors/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Default for ArrayToken {
}

/// Bounded channel based on a preallocated array.
pub struct Channel<T> {
pub(crate) struct Channel<T> {
/// The head of the channel.
///
/// This value is a "stamp" consisting of an index into the buffer, a mark bit, and a lap, but
Expand Down Expand Up @@ -95,7 +95,7 @@ pub struct Channel<T> {

impl<T> Channel<T> {
/// Creates a bounded channel of capacity `cap`.
pub fn with_capacity(cap: usize) -> Self {
pub(crate) fn with_capacity(cap: usize) -> Self {
assert!(cap > 0, "capacity must be positive");

// Compute constants `mark_bit` and `one_lap`.
Expand Down Expand Up @@ -138,12 +138,12 @@ impl<T> Channel<T> {
}

/// Returns a receiver handle to the channel.
pub fn receiver(&self) -> Receiver<'_, T> {
pub(crate) fn receiver(&self) -> Receiver<'_, T> {
Receiver(self)
}

/// Returns a sender handle to the channel.
pub fn sender(&self) -> Sender<'_, T> {
pub(crate) fn sender(&self) -> Sender<'_, T> {
Sender(self)
}

Expand Down Expand Up @@ -219,7 +219,7 @@ impl<T> Channel<T> {
}

/// Writes a message into the channel.
pub unsafe fn write(&self, token: &mut Token, msg: T) -> Result<(), T> {
pub(crate) unsafe fn write(&self, token: &mut Token, msg: T) -> Result<(), T> {
// If there is no slot, the channel is disconnected.
if token.array.slot.is_null() {
return Err(msg);
Expand Down Expand Up @@ -309,7 +309,7 @@ impl<T> Channel<T> {
}

/// Reads a message from the channel.
pub unsafe fn read(&self, token: &mut Token) -> Result<T, ()> {
pub(crate) unsafe fn read(&self, token: &mut Token) -> Result<T, ()> {
if token.array.slot.is_null() {
// The channel is disconnected.
return Err(());
Expand All @@ -327,7 +327,7 @@ impl<T> Channel<T> {
}

/// Attempts to send a message into the channel.
pub fn try_send(&self, msg: T) -> Result<(), TrySendError<T>> {
pub(crate) fn try_send(&self, msg: T) -> Result<(), TrySendError<T>> {
let token = &mut Token::default();
if self.start_send(token) {
unsafe { self.write(token, msg).map_err(TrySendError::Disconnected) }
Expand All @@ -337,7 +337,11 @@ impl<T> Channel<T> {
}

/// Sends a message into the channel.
pub fn send(&self, msg: T, deadline: Option<Instant>) -> Result<(), SendTimeoutError<T>> {
pub(crate) fn send(
&self,
msg: T,
deadline: Option<Instant>,
) -> Result<(), SendTimeoutError<T>> {
let token = &mut Token::default();
loop {
// Try sending a message several times.
Expand Down Expand Up @@ -386,7 +390,7 @@ impl<T> Channel<T> {
}

/// Attempts to receive a message without blocking.
pub fn try_recv(&self) -> Result<T, TryRecvError> {
pub(crate) fn try_recv(&self) -> Result<T, TryRecvError> {
let token = &mut Token::default();

if self.start_recv(token) {
Expand All @@ -397,7 +401,7 @@ impl<T> Channel<T> {
}

/// Receives a message from the channel.
pub fn recv(&self, deadline: Option<Instant>) -> Result<T, RecvTimeoutError> {
pub(crate) fn recv(&self, deadline: Option<Instant>) -> Result<T, RecvTimeoutError> {
let token = &mut Token::default();
loop {
// Try receiving a message several times.
Expand Down Expand Up @@ -448,7 +452,7 @@ impl<T> Channel<T> {
}

/// Returns the current number of messages inside the channel.
pub fn len(&self) -> usize {
pub(crate) fn len(&self) -> usize {
loop {
// Load the tail, then load the head.
let tail = self.tail.load(Ordering::SeqCst);
Expand All @@ -473,14 +477,14 @@ impl<T> Channel<T> {
}

/// Returns the capacity of the channel.
pub fn capacity(&self) -> Option<usize> {
pub(crate) fn capacity(&self) -> Option<usize> {
Some(self.cap)
}

/// Disconnects the channel and wakes up all blocked senders and receivers.
///
/// Returns `true` if this call disconnected the channel.
pub fn disconnect(&self) -> bool {
pub(crate) fn disconnect(&self) -> bool {
let tail = self.tail.fetch_or(self.mark_bit, Ordering::SeqCst);

if tail & self.mark_bit == 0 {
Expand All @@ -493,12 +497,12 @@ impl<T> Channel<T> {
}

/// Returns `true` if the channel is disconnected.
pub fn is_disconnected(&self) -> bool {
pub(crate) fn is_disconnected(&self) -> bool {
self.tail.load(Ordering::SeqCst) & self.mark_bit != 0
}

/// Returns `true` if the channel is empty.
pub fn is_empty(&self) -> bool {
pub(crate) fn is_empty(&self) -> bool {
let head = self.head.load(Ordering::SeqCst);
let tail = self.tail.load(Ordering::SeqCst);

Expand All @@ -510,7 +514,7 @@ impl<T> Channel<T> {
}

/// Returns `true` if the channel is full.
pub fn is_full(&self) -> bool {
pub(crate) fn is_full(&self) -> bool {
let tail = self.tail.load(Ordering::SeqCst);
let head = self.head.load(Ordering::SeqCst);

Expand Down Expand Up @@ -558,10 +562,10 @@ impl<T> Drop for Channel<T> {
}

/// Receiver handle to a channel.
pub struct Receiver<'a, T>(&'a Channel<T>);
pub(crate) struct Receiver<'a, T>(&'a Channel<T>);

/// Sender handle to a channel.
pub struct Sender<'a, T>(&'a Channel<T>);
pub(crate) struct Sender<'a, T>(&'a Channel<T>);

impl<T> SelectHandle for Receiver<'_, T> {
fn try_select(&self, token: &mut Token) -> bool {
Expand Down
22 changes: 11 additions & 11 deletions crossbeam-channel/src/flavors/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use crate::select::{Operation, SelectHandle, Token};
use crate::utils;

/// Result of a receive operation.
pub type AtToken = Option<Instant>;
pub(crate) type AtToken = Option<Instant>;

/// Channel that delivers a message at a certain moment in time
pub struct Channel {
pub(crate) struct Channel {
/// The instant at which the message will be delivered.
delivery_time: Instant,

Expand All @@ -26,21 +26,21 @@ pub struct Channel {
impl Channel {
/// Creates a channel that delivers a message at a certain instant in time.
#[inline]
pub fn new_deadline(when: Instant) -> Self {
pub(crate) fn new_deadline(when: Instant) -> Self {
Channel {
delivery_time: when,
received: AtomicBool::new(false),
}
}
/// Creates a channel that delivers a message after a certain duration of time.
#[inline]
pub fn new_timeout(dur: Duration) -> Self {
pub(crate) fn new_timeout(dur: Duration) -> Self {
Self::new_deadline(Instant::now() + dur)
}

/// Attempts to receive a message without blocking.
#[inline]
pub fn try_recv(&self) -> Result<Instant, TryRecvError> {
pub(crate) fn try_recv(&self) -> Result<Instant, TryRecvError> {
// We use relaxed ordering because this is just an optional optimistic check.
if self.received.load(Ordering::Relaxed) {
// The message has already been received.
Expand All @@ -64,7 +64,7 @@ impl Channel {

/// Receives a message from the channel.
#[inline]
pub fn recv(&self, deadline: Option<Instant>) -> Result<Instant, RecvTimeoutError> {
pub(crate) fn recv(&self, deadline: Option<Instant>) -> Result<Instant, RecvTimeoutError> {
// We use relaxed ordering because this is just an optional optimistic check.
if self.received.load(Ordering::Relaxed) {
// The message has already been received.
Expand Down Expand Up @@ -103,13 +103,13 @@ impl Channel {

/// Reads a message from the channel.
#[inline]
pub unsafe fn read(&self, token: &mut Token) -> Result<Instant, ()> {
pub(crate) unsafe fn read(&self, token: &mut Token) -> Result<Instant, ()> {
token.at.ok_or(())
}

/// Returns `true` if the channel is empty.
#[inline]
pub fn is_empty(&self) -> bool {
pub(crate) fn is_empty(&self) -> bool {
// We use relaxed ordering because this is just an optional optimistic check.
if self.received.load(Ordering::Relaxed) {
return true;
Expand All @@ -127,13 +127,13 @@ impl Channel {

/// Returns `true` if the channel is full.
#[inline]
pub fn is_full(&self) -> bool {
pub(crate) fn is_full(&self) -> bool {
!self.is_empty()
}

/// Returns the number of messages in the channel.
#[inline]
pub fn len(&self) -> usize {
pub(crate) fn len(&self) -> usize {
if self.is_empty() {
0
} else {
Expand All @@ -143,7 +143,7 @@ impl Channel {

/// Returns the capacity of the channel.
#[inline]
pub fn capacity(&self) -> Option<usize> {
pub(crate) fn capacity(&self) -> Option<usize> {
Some(1)
}
}
Expand Down
Loading