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

eyeball-im: Switch to imbl #10

Merged
merged 1 commit into from
Mar 16, 2023
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
3 changes: 3 additions & 0 deletions eyeball-im/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# unreleased

- Switch from the unmaintained `im` crate to the maintained fork `imbl`
2 changes: 1 addition & 1 deletion eyeball-im/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ all-features = true

[dependencies]
futures-core.workspace = true
im = "15.1.0"
imbl = "2.0.0"
tokio.workspace = true
tokio-stream.workspace = true
tracing = { workspace = true, optional = true }
Expand Down
17 changes: 8 additions & 9 deletions eyeball-im/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use std::{
};

use futures_core::Stream;
use im::Vector;
use imbl::Vector;
use tokio::sync::broadcast::{self, Sender};
use tokio_stream::wrappers::{errors::BroadcastStreamRecvError, BroadcastStream};

/// An ordered list of elements that broadcasts any changes made to it.
pub struct ObservableVector<T: Clone> {
pub struct ObservableVector<T> {
values: Vector<T>,
sender: Sender<BroadcastMessage<T>>,
}
Expand Down Expand Up @@ -180,7 +180,7 @@ impl<T: Clone + Send + Sync + 'static> Default for ObservableVector<T> {

impl<T> fmt::Debug for ObservableVector<T>
where
T: Clone + fmt::Debug,
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ObservableVector").field("values", &self.values).finish_non_exhaustive()
Expand All @@ -189,7 +189,7 @@ where

// Note: No DerefMut because all mutating must go through inherent methods that
// notify subscribers
impl<T: Clone> ops::Deref for ObservableVector<T> {
impl<T> ops::Deref for ObservableVector<T> {
type Target = Vector<T>;

fn deref(&self) -> &Self::Target {
Expand All @@ -206,7 +206,7 @@ impl<T: Clone + Send + Sync + 'static> From<Vector<T>> for ObservableVector<T> {
}

#[derive(Clone)]
struct BroadcastMessage<T: Clone> {
struct BroadcastMessage<T> {
diff: VectorDiff<T>,
state: Vector<T>,
}
Expand All @@ -217,12 +217,12 @@ struct BroadcastMessage<T: Clone> {
/// other futures-related crates have extension traits with convenience
/// methods).
#[derive(Debug)]
pub struct VectorSubscriber<T: Clone> {
pub struct VectorSubscriber<T> {
inner: BroadcastStream<BroadcastMessage<T>>,
must_reset: bool,
}

impl<T: Clone> VectorSubscriber<T> {
impl<T> VectorSubscriber<T> {
const fn new(inner: BroadcastStream<BroadcastMessage<T>>) -> Self {
Self { inner, must_reset: false }
}
Expand Down Expand Up @@ -258,8 +258,7 @@ impl<T: Clone + Send + Sync + 'static> Stream for VectorSubscriber<T> {

/// A change to an [`ObservableVector`].
#[derive(Clone, Debug, PartialEq, Eq)]
// FIXME: Clone bound currently needed for derived `impl Debug for Vector<T>`
pub enum VectorDiff<T: Clone> {
pub enum VectorDiff<T> {
/// Multiple elements were appended.
Append {
/// The appended elements.
Expand Down
2 changes: 1 addition & 1 deletion eyeball-im/tests/it.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use im::Vector;
use imbl::Vector;
use tokio_stream::StreamExt as _;

use eyeball_im::{ObservableVector, VectorDiff};
Expand Down