chore(rust): make listener_address in profile channel listener non optional
@@ -9,16 +9,17 @@ pub(crate) struct ProfileChannelListener<T: TrustPolicy, P: ProfileTrait, V: XXV
trust_policy: T,
profile: P,
vault: V,
- listener_address: Option<Address>,
+ listener_address: Address,
}
impl<T: TrustPolicy, P: ProfileTrait, V: XXVault> ProfileChannelListener<T, P, V> {
pub fn new(trust_policy: T, profile: P, vault: V) -> Self {
+ let listener_address: Address = random();
ProfileChannelListener {
trust_policy,
profile,
vault,
- listener_address: None,
+ listener_address,
}
}
}
@@ -29,24 +30,21 @@ impl<T: TrustPolicy, P: ProfileTrait, V: XXVault> Worker for ProfileChannelListe
type Context = Context;
async fn initialize(&mut self, ctx: &mut Self::Context) -> Result<()> {
- let listener_address: Address = random();
let new_key_exchanger = XXNewKeyExchanger::new(self.vault.clone());
let vault = self.vault.clone();
SecureChannel::create_listener_extended(
ctx,
- listener_address.clone(),
+ self.listener_address.clone(),
new_key_exchanger,
vault,
)
.await?;
- self.listener_address = Some(listener_address);
-
Ok(())
}
async fn shutdown(&mut self, ctx: &mut Self::Context) -> Result<()> {
- ctx.stop_worker(self.listener_address.take().unwrap()).await
+ ctx.stop_worker(self.listener_address.clone()).await
}
async fn handle_message(
@@ -59,7 +57,7 @@ impl<T: TrustPolicy, P: ProfileTrait, V: XXVault> Worker for ProfileChannelListe
ctx,
&mut self.profile,
trust_policy,
- self.listener_address.clone().unwrap(),
+ self.listener_address.clone(),
msg,
)
.await
