Skip to content

Commit

Permalink
Rename crate
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfl0wer committed Jul 13, 2024
1 parent a605975 commit 4ddcdbb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "spectra"
name = "pubserve"
license = "MPL-2.0"
version = "1.0.0"
edition = "2021"
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# spectra
# pubserve

> Publish and observe.
Simple, generic observer pattern implementation for Rust.

## Usage

spectra is really simple to use. Start by creating a `Publisher` for your data type:
pubserve is really simple to use. Start by creating a `Publisher` for your data type:

```rust
use spectra::Publisher;
use pubserve::Publisher;

let publisher = Publisher::<i32>::new();
```

Then, create a subscriber that will listen to the publisher:

```rust
use spectra::Subscriber;
use pubserve::Subscriber;

struct MySubscriber;

Expand All @@ -30,7 +32,7 @@ impl Subscriber<i32> for MySubscriber {
Finally, subscribe the observer to the publisher:

```rust
use spectra::ReferenceCounted;
use pubserve::ReferenceCounted;

let observer = MySubscriber;
let reference = ReferenceCounted::new(&observer);
Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub trait Subscriber<T> {
///
/// # Example
/// ```
/// use spectra::Publisher;
/// use pubserve::Publisher;
/// let mut publisher = Publisher::<String>::new();
/// publisher.publish("Hello, World!".to_string()); // .await, if async feature is enabled
/// ```
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<T> Publisher<T> {
/// identical.
///
/// ```
/// use spectra::{Publisher, Subscriber};
/// use pubserve::{Publisher, Subscriber};
///
/// struct MySubscriber;
///
Expand All @@ -102,7 +102,7 @@ impl<T> Publisher<T> {
///
/// let mut publisher = Publisher::<String>::new();
/// let subscriber = MySubscriber;
/// let rc_subscriber = spectra::ReferenceCounted::new(subscriber);
/// let rc_subscriber = pubserve::ReferenceCounted::new(subscriber);
/// publisher.subscribe(rc_subscriber.clone());
/// // This will print "Received this message: Hello, World!"
/// publisher.publish("Hello, World!".to_string());
Expand All @@ -113,7 +113,7 @@ impl<T> Publisher<T> {
/// // The following subscribing/unsubscribing will NOT work. If you do not understand why,
/// // please read up on how reference counting works in Rust.
/// publisher.subscribe(rc_subscriber.clone());
/// publisher.unsubscribe(spectra::ReferenceCounted::new(MySubscriber));
/// publisher.unsubscribe(pubserve::ReferenceCounted::new(MySubscriber));
/// ```
pub fn subscribe(&mut self, subscriber: ReferenceCounted<dyn Subscriber<T>>) {
self.subscribers.push(subscriber);
Expand All @@ -135,7 +135,7 @@ impl<T> Publisher<T> {
/// identical.
///
/// ```
/// use spectra::{Publisher, Subscriber};
/// use pubserve::{Publisher, Subscriber};
///
/// struct MySubscriber;
///
Expand All @@ -148,7 +148,7 @@ impl<T> Publisher<T> {
///
/// let mut publisher = Publisher::<String>::new();
/// let subscriber = MySubscriber;
/// let rc_subscriber = spectra::ReferenceCounted::new(subscriber);
/// let rc_subscriber = pubserve::ReferenceCounted::new(subscriber);
/// publisher.subscribe(rc_subscriber.clone());
/// // This will print "Received this message: Hello, World!"
/// publisher.publish("Hello, World!".to_string());
Expand All @@ -159,7 +159,7 @@ impl<T> Publisher<T> {
/// // The following subscribing/unsubscribing will NOT work. If you do not understand why,
/// // please read up on how reference counting works in Rust.
/// publisher.subscribe(rc_subscriber.clone());
/// publisher.unsubscribe(spectra::ReferenceCounted::new(MySubscriber));
/// publisher.unsubscribe(pubserve::ReferenceCounted::new(MySubscriber));
/// ```
pub fn unsubscribe(&mut self, subscriber: ReferenceCounted<dyn Subscriber<T>>) {
self.subscribers
Expand Down

0 comments on commit 4ddcdbb

Please sign in to comment.