Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code shared from the Rust Playground
use std::net::{SocketAddr, UdpSocket};
use std::sync::{Arc, Mutex};
use serde::Serialize;
use serde_json::Value;
pub struct Peer {
ip: SocketAddr,
pub fn foo(_socket: &UdpSocket, _packet: Value, target_addr: SocketAddr, peers: Arc<Mutex<Vec<Peer>>>) {
let lock = peers.lock().expect("cannot lock the peers");
if !lock.iter().find(|x| x.ip == target_addr).is_some() {
let _packet = write_packet(&*lock);
fn write_packet<T: Serialize>(_data: &T) -> String { serde_json::to_string(_data).unwrap() }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.