refactor: remove AsMut<Pubsub> in favor of getter

neither looks too good but AsMut<Pubsub> trick cannot be played with
multiple components so there goes that idea.
This commit is contained in:
Joonas Koivunen 2020-03-30 19:17:04 +03:00 committed by Joonas Koivunen
parent a068e2565b
commit cd26d39857
2 changed files with 7 additions and 9 deletions

View File

@ -615,24 +615,24 @@ impl<Types: SwarmTypes> Future for IpfsFuture<Types> {
let _ = ret.send(addresses);
}
IpfsEvent::PubsubSubscribe(topic, ret) => {
let _ = ret.send(self.swarm.as_mut().subscribe(topic));
let _ = ret.send(self.swarm.pubsub().subscribe(topic));
}
IpfsEvent::PubsubUnsubscribe(topic, ret) => {
let _ = ret.send(self.swarm.as_mut().unsubscribe(topic));
let _ = ret.send(self.swarm.pubsub().unsubscribe(topic));
}
IpfsEvent::PubsubPublish(topic, data, ret) => {
self.swarm.as_mut().publish(topic, data);
self.swarm.pubsub().publish(topic, data);
let _ = ret.send(());
}
IpfsEvent::PubsubPeers(Some(topic), ret) => {
let topic = libp2p::floodsub::Topic::new(topic);
let _ = ret.send(self.swarm.as_mut().subscribed_peers(&topic));
let _ = ret.send(self.swarm.pubsub().subscribed_peers(&topic));
}
IpfsEvent::PubsubPeers(None, ret) => {
let _ = ret.send(self.swarm.as_mut().known_peers());
let _ = ret.send(self.swarm.pubsub().known_peers());
}
IpfsEvent::PubsubSubscribed(ret) => {
let _ = ret.send(self.swarm.as_mut().subscribed_topics());
let _ = ret.send(self.swarm.pubsub().subscribed_topics());
}
IpfsEvent::WantList(peer, ret) => {
todo!()

View File

@ -232,10 +232,8 @@ impl<TSwarmTypes: SwarmTypes> Behaviour<TSwarmTypes> {
//let hash = Multihash::from_bytes(cid.to_bytes()).unwrap();
//self.kademlia.remove_providing(&hash);
}
}
impl<T: SwarmTypes> std::convert::AsMut<Pubsub> for Behaviour<T> {
fn as_mut(&mut self) -> &mut Pubsub {
pub fn pubsub(&mut self) -> &mut Pubsub {
&mut self.pubsub
}
}