Write the code for a library in Rust, using the observer pattern based on the library RxJS
Sure, here's an example implementation of an observer pattern in Rust based on the RxJS library:

```rust
use std::sync::{Arc, Mutex};
use std::collections::HashMap;

type EventHandler<T> = Arc<Mutex<Box<dyn FnMut(T)>>>;

struct Observable<T> {
    observers: HashMap<String, EventHandler<T>>,
}

impl<T> Observable<T> {
    fn new() -> Self {
        Observable {
            observers: HashMap::new(),
        }
    }

    fn subscribe(&mut self, name: &str, handler: EventHandler<T>) {
        self.observers.insert(String::from(name), handler);
    }

    fn unsubscribe(&mut self, name: &str) {
        self.observers.remove(name);
    }

    fn notify(&mut self, data: T) {
        for (_, handler) in self.observers.iter_mut() {
            handler.lock().unwrap()(data.clone());
        }
    }
}
```

In this example, we have a generic Observable struct that stores a list of observers as EventHandler closures. The subscribe method adds a new observer to the list with a given name, and the unsubscribe method removes an observer by name. The notify method sends data to all the registered observers, triggering their respective handlers.

To use this observer pattern in your Rust code, you can create a new instance of Observable, subscribe to it using subscribe, and then call notify with data whenever you want to notify the observers. For example:

```rust
let mut observable = Observable::<i32>::new();

let handler1 = Arc::new(Mutex::new(Box::new(|data| {
    println!(Observer 1 received data: {}, data);
})));
observable.subscribe(observer1, handler1);

let handler2 = Arc::new(Mutex::new(Box::new(|data| {
    println!(Observer 2 received data: {}, data);
})));
observable.subscribe(observer2, handler2);

observable.notify(42);

observable.unsubscribe(observer1);
observable.notify(13);
```

This code creates a new Observable that emits i32 data, subscribes two observers with different handlers, notifies the observers with data, unsubscribes one observer, and then notifies the remaining observer with new data.