Tag : rust

I would like to make a function that can take either owned value, or a reference that can be cloned into an owned value. This way an owned value can be passed in without extra cloning. It seems I am able to do it with a custom trait specifically for String/&str, but I couldn’t find anything similar/generic in s..

Read more

loop { select! { Ok(Some(line)) = stdin.next_line() => { handle_input(&mut swarm, line.to_string()).await?; } event = swarm.select_next_some() => match event { SwarmEvent::Behaviour(P2PBehaviourEvent::Mdns(mdns::Event::Discovered(list))) => { for (peer_id, _multiaddr) in list { println!(“Discovered a new peer: {peer_id}”); swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer_id); } }, SwarmEvent::Behaviour(P2PBehaviourEvent::Mdns(mdns::Event::Expired(list))) => { for (peer_id, _multiaddr) in list { println!(“Peer {peer_id} has expired”); swarm.behaviour_mut().gossipsub.remove_explicit_peer(&peer_id); } }, SwarmEvent::Behaviour(P2PBehaviourEvent::Gossipsub(gossipsub::Event::Message { ..

Read more