Indicate that method call can fail

This commit is contained in:
bitfl0wer 2023-04-27 22:38:41 +02:00
parent 77ff7d6510
commit 656acad356
No known key found for this signature in database
GPG Key ID: 84BBB60DF895ABF2
1 changed files with 6 additions and 3 deletions

View File

@ -1,3 +1,5 @@
use crate::errors::ObserverError;
#[derive(Debug)]
pub struct Gateway {}
@ -24,12 +26,13 @@ impl<'a> GatewayEvent<'a> {
self.is_observed
}
pub fn subscribe(&mut self, observable: &'a dyn Observer) {
pub fn subscribe(&mut self, observable: &'a dyn Observer) -> Option<ObserverError> {
if self.is_observed {
return;
return Some(ObserverError::AlreadySubscribedError);
}
self.is_observed = true;
self.observers.push(observable)
self.observers.push(observable);
None
}
pub fn unsubscribe(&mut self, observable: &'a dyn Observer) {