Fail compilation on unreachable public exports
This enables the unreachable_pub rustc lint so that we don't end up exposing unconstructable types again Ref: https://github.com/caio/foca/issues/24
- Id
- 04fd49c75d478792abc6fce1e93cab44a7080352
- Author
- Caio
- Commit time
- 2023-07-10T12:35:25+02:00
Modified src/broadcast.rs
where
T: Invalidates + AsRef<[u8]>,
{
- pub fn new() -> Self {
+ pub(crate) fn new() -> Self {
Self {
storage: Vec::new(),
}
}
- pub fn len(&self) -> usize {
+ pub(crate) fn len(&self) -> usize {
self.storage.len()
}
- pub fn add_or_replace(&mut self, value: T, max_tx: usize) {
+ pub(crate) fn add_or_replace(&mut self, value: T, max_tx: usize) {
let new_node = Entry {
remaining_tx: max_tx,
value,
self.storage.insert(position, new_node);
}
- pub fn fill(&mut self, mut buffer: impl BufMut, max_items: usize) -> usize {
+ pub(crate) fn fill(&mut self, mut buffer: impl BufMut, max_items: usize) -> usize {
if self.storage.is_empty() {
return 0;
}
num_taken
}
- pub fn is_sorted(&self) -> bool {
+ pub(crate) fn is_sorted(&self) -> bool {
// Future: `is_sorted` from https://github.com/rust-lang/rfcs/pull/2351
self.storage[..]
.windows(2)
.all(|w| w[0].remaining_tx <= w[1].remaining_tx)
}
- pub fn is_empty(&self) -> bool {
+ pub(crate) fn is_empty(&self) -> bool {
self.storage.is_empty()
}
}
Modified src/codec.rs
use crate::{Header, Member};
#[cfg(feature = "bincode-codec")]
-pub mod bincode_impl;
+pub(crate) mod bincode_impl;
#[cfg(feature = "postcard-codec")]
-pub mod postcard_impl;
+pub(crate) mod postcard_impl;
/// A Codec is responsible to encoding and decoding the data that
/// is sent between cluster members.
Modified src/lib.rs
//!
#![forbid(unsafe_code)]
#![no_std]
-#![deny(missing_docs)]
+#![deny(missing_docs, unreachable_pub)]
#![deny(rustdoc::broken_intra_doc_links)]
extern crate alloc;
self.incarnation
}
- pub fn probe(&self) -> &Probe<T> {
+ pub(crate) fn probe(&self) -> &Probe<T> {
&self.probe
}
Modified src/member.rs
#[cfg(test)]
impl<T> Members<T> {
- pub fn len(&self) -> usize {
+ pub(crate) fn len(&self) -> usize {
self.inner.len()
}
}
impl<T: PartialEq + Clone> Members<T> {
- pub fn num_active(&self) -> usize {
+ pub(crate) fn num_active(&self) -> usize {
self.num_active
}
- pub fn new(inner: Vec<Member<T>>) -> Self {
+ pub(crate) fn new(inner: Vec<Member<T>>) -> Self {
// XXX This doesn't prevent someone initializing with
// duplicated members... Not a problem (yet?) since
// inner is always empty outside of tests
// Next member that's considered active
// Chosen at random (shuffle + round-robin)
- pub fn next(&mut self, mut rng: impl Rng) -> Option<&Member<T>> {
+ pub(crate) fn next(&mut self, mut rng: impl Rng) -> Option<&Member<T>> {
// Round-robin with a shuffle at the end
if self.cursor >= self.inner.len() {
self.inner.shuffle(&mut rng);
/// a high chance that every member will be *pinged* periodically
/// and using the same logic for other "pick random member"
/// mechanisms might break the math.
- pub fn choose_active_members<F>(
+ pub(crate) fn choose_active_members<F>(
&self,
wanted: usize,
output: &mut Vec<Member<T>>,
}
}
- pub fn remove_if_down(&mut self, id: &T) -> Option<Member<T>> {
+ pub(crate) fn remove_if_down(&mut self, id: &T) -> Option<Member<T>> {
let position = self
.inner
.iter()
position.map(|pos| self.inner.swap_remove(pos))
}
- pub fn iter_active(&self) -> impl Iterator<Item = &Member<T>> {
+ pub(crate) fn iter_active(&self) -> impl Iterator<Item = &Member<T>> {
self.inner.iter().filter(|m| m.is_active())
}
- pub fn apply_existing_if<F: Fn(&Member<T>) -> bool>(
+ pub(crate) fn apply_existing_if<F: Fn(&Member<T>) -> bool>(
&mut self,
update: Member<T>,
condition: F,
}
}
- pub fn apply(&mut self, update: Member<T>, mut rng: impl Rng) -> ApplySummary {
+ pub(crate) fn apply(&mut self, update: Member<T>, mut rng: impl Rng) -> ApplySummary {
self.apply_existing_if(update.clone(), |_member| true)
.unwrap_or_else(|| {
// Unknown member, we'll register it
#[derive(Debug, Clone, PartialEq)]
#[must_use]
pub(crate) struct ApplySummary {
- pub is_active_now: bool,
- pub apply_successful: bool,
- pub changed_active_set: bool,
+ pub(crate) is_active_now: bool,
+ pub(crate) apply_successful: bool,
+ pub(crate) changed_active_set: bool,
}
#[cfg(test)]
Modified src/probe.rs
// FIXME This whole thing is ugly AF :(
-pub struct Probe<T> {
+pub(crate) struct Probe<T> {
direct: Option<Member<T>>,
indirect: Vec<T>,
probe_number: ProbeNumber,
}
impl<T: Clone + PartialEq> Probe<T> {
- pub fn new(indirect: Vec<T>) -> Self {
+ pub(crate) fn new(indirect: Vec<T>) -> Self {
Self {
indirect,
direct: None,
}
#[must_use]
- pub fn start(&mut self, target: Member<T>) -> ProbeNumber {
+ pub(crate) fn start(&mut self, target: Member<T>) -> ProbeNumber {
self.clear();
self.direct = Some(target);
self.probe_number = self.probe_number.wrapping_add(1);
self.probe_number
}
- pub fn clear(&mut self) {
+ pub(crate) fn clear(&mut self) {
self.direct = None;
self.indirect.clear();
self.direct_ack_ok = false;
// do NOT reset probe_number
}
- pub fn mark_indirect_probe_stage_reached(&mut self) {
+ pub(crate) fn mark_indirect_probe_stage_reached(&mut self) {
self.reached_indirect_probe_stage = true;
}
- pub fn validate(&self) -> bool {
+ pub(crate) fn validate(&self) -> bool {
// A probe that hasn't been started is
// valid
self.direct.is_none()
|| self.reached_indirect_probe_stage
}
- pub fn take_failed(&mut self) -> Option<Member<T>> {
+ pub(crate) fn take_failed(&mut self) -> Option<Member<T>> {
if !self.succeeded() {
self.direct.take()
} else {
}
#[cfg(any(feature = "tracing", test))]
- pub fn target(&self) -> Option<&T> {
+ pub(crate) fn target(&self) -> Option<&T> {
self.direct.as_ref().map(|probed| probed.id())
}
- pub fn is_probing(&self, id: &T) -> bool {
+ pub(crate) fn is_probing(&self, id: &T) -> bool {
self.direct
.as_ref()
.map(|probed| probed.id() == id)
.unwrap_or(false)
}
- pub fn succeeded(&self) -> bool {
+ pub(crate) fn succeeded(&self) -> bool {
self.direct_ack_ok || self.indirect_ack_count > 0
}
- pub fn receive_ack(&mut self, from: &T, probeno: ProbeNumber) -> bool {
+ pub(crate) fn receive_ack(&mut self, from: &T, probeno: ProbeNumber) -> bool {
if probeno == self.probe_number
&& self
.direct
}
}
- pub fn expect_indirect_ack(&mut self, from: T) {
+ pub(crate) fn expect_indirect_ack(&mut self, from: T) {
debug_assert!(self
.direct
.as_ref()
self.indirect.push(from);
}
- pub fn receive_indirect_ack(&mut self, from: &T, probeno: ProbeNumber) -> bool {
+ pub(crate) fn receive_indirect_ack(&mut self, from: &T, probeno: ProbeNumber) -> bool {
if self.probe_number != probeno {
return false;
}
Modified src/testing.rs
use crate::{Codec, Header, Identity, Member, Message, Notification, Runtime, State, Timer};
#[derive(Debug, Clone, Copy, PartialOrd, Ord)]
-pub struct ID {
+pub(crate) struct ID {
id: u8,
bump: u8,
rejoinable: bool,
impl Eq for ID {}
impl ID {
- pub fn new(id: u8) -> Self {
+ pub(crate) fn new(id: u8) -> Self {
ID::new_with_bump(id, 0)
}
- pub fn new_with_bump(id: u8, bump: u8) -> Self {
+ pub(crate) fn new_with_bump(id: u8, bump: u8) -> Self {
Self {
id,
bump,
}
}
- pub fn rejoinable(mut self) -> Self {
+ pub(crate) fn rejoinable(mut self) -> Self {
self.rejoinable = true;
self
}
- pub fn serialize_into(&self, mut buf: impl BufMut) -> Result<(), BadCodecError> {
+ pub(crate) fn serialize_into(&self, mut buf: impl BufMut) -> Result<(), BadCodecError> {
if buf.remaining_mut() >= 2 {
buf.put_u8(self.id);
buf.put_u8(self.bump);
}
}
- pub fn deserialize_from(mut buf: impl Buf) -> Result<Self, BadCodecError> {
+ pub(crate) fn deserialize_from(mut buf: impl Buf) -> Result<Self, BadCodecError> {
if buf.remaining() >= 2 {
Ok(Self {
id: buf.get_u8(),
}
}
-pub struct BadCodec;
+pub(crate) struct BadCodec;
#[derive(Debug, PartialEq, Eq)]
-pub enum BadCodecError {
+pub(crate) enum BadCodecError {
BufTooSmall,
BadMessageID(u8),
BadStateByte(u8),
}
#[derive(Debug, Clone)]
-pub struct InMemoryRuntime {
+pub(crate) struct InMemoryRuntime {
notifications: Vec<Notification<ID>>,
to_send: Vec<(ID, Bytes)>,
to_schedule: Vec<(Timer<ID>, Duration)>,
}
impl InMemoryRuntime {
- pub fn new() -> Self {
+ pub(crate) fn new() -> Self {
Self {
notifications: Vec::new(),
to_send: Vec::new(),
}
}
- pub fn clear(&mut self) {
+ pub(crate) fn clear(&mut self) {
self.notifications.clear();
self.to_send.clear();
self.to_schedule.clear();
}
- pub fn take_all_data(&mut self) -> Vec<(ID, Bytes)> {
+ pub(crate) fn take_all_data(&mut self) -> Vec<(ID, Bytes)> {
core::mem::take(&mut self.to_send)
}
- pub fn take_data(&mut self, dst: ID) -> Option<Bytes> {
+ pub(crate) fn take_data(&mut self, dst: ID) -> Option<Bytes> {
let position = self.to_send.iter().position(|(to, _data)| to == &dst)?;
let taken = self.to_send.swap_remove(position);
Some(taken.1)
}
- pub fn take_notification(&mut self, wanted: Notification<ID>) -> Option<Notification<ID>> {
+ pub(crate) fn take_notification(
+ &mut self,
+ wanted: Notification<ID>,
+ ) -> Option<Notification<ID>> {
let position = self
.notifications
.iter()
Some(taken)
}
- pub fn take_scheduling(&mut self, timer: Timer<ID>) -> Option<Duration> {
+ pub(crate) fn take_scheduling(&mut self, timer: Timer<ID>) -> Option<Duration> {
let position = self
.to_schedule
.iter()
Some(taken.1)
}
- pub fn find_scheduling<F>(&self, predicate: F) -> Option<&Timer<ID>>
+ pub(crate) fn find_scheduling<F>(&self, predicate: F) -> Option<&Timer<ID>>
where
F: Fn(&Timer<ID>) -> bool,
{
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
-pub struct TrivialID(u64);
+pub(crate) struct TrivialID(u64);
#[cfg(any(feature = "bincode-codec", feature = "postcard-codec"))]
-pub fn verify_codec_roundtrip<C: Codec<TrivialID>>(mut codec: C) -> Result<(), C::Error> {
+pub(crate) fn verify_codec_roundtrip<C: Codec<TrivialID>>(mut codec: C) -> Result<(), C::Error> {
let mut buf = Vec::new();
let payload = Header {