Bump versions, avoid some clones
Some checks failed
CI / Formatting (push) Has been cancelled

This commit is contained in:
Michael Bradley 2025-12-12 23:53:16 -05:00
parent 3921537360
commit 32de6d5a38
Signed by: MichaelBradley
SSH key fingerprint: SHA256:o/aaeYtRubILK7OYYjYP12DmU7BsPUhKji1AgaQ+ge4
4 changed files with 739 additions and 770 deletions

1459
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -39,8 +39,8 @@ incremental = false
debug = false debug = false
[dependencies] [dependencies]
avian2d = { version = "0.4.0", features = ["serialize", "simd"] } avian2d = { version = "0.4.1", features = ["serialize", "simd"] }
bevy = { version = "0.17.2", default-features = false, features = [ bevy = { version = "0.17.3", default-features = false, features = [
"bevy_color", "bevy_color",
"bevy_core_pipeline", "bevy_core_pipeline",
"bevy_remote", "bevy_remote",
@ -55,15 +55,15 @@ bevy = { version = "0.17.2", default-features = false, features = [
"std", "std",
"wayland", "wayland",
] } ] }
bevy_rand = { version = "0.12.0", features = ["wyrand", "std"] } bevy_rand = { version = "0.12.1", features = ["wyrand", "std"] }
clap = { version = "4.5.48", features = ["derive"] } clap = { version = "4.5.53", features = ["derive"] }
crossbeam-channel = "0.5.15" crossbeam-channel = "0.5.15"
log = { version = "0.4.28", features = ["release_max_level_warn"] } log = { version = "0.4.29", features = ["release_max_level_warn"] }
rand = { version = "0.9.2", default-features = false, features = [ rand = { version = "0.9.2", default-features = false, features = [
"std", "std",
"thread_rng", "thread_rng",
] } ] }
uuid = { version = "1.18.1", features = ["v4", "fast-rng"] } uuid = { version = "1.19.0", features = ["v4", "fast-rng"] }
wyrand = "0.3.2" wyrand = "0.3.2"
[features] [features]

View file

@ -40,6 +40,19 @@ impl PeerReceiveTiming {
} }
} }
// TODO: this is a pretty minimal error type to avoid panicking, it should at least impl Error or something
#[derive(Clone, Copy, Debug)]
pub enum NetworkConvertError {
FromSliceError(TryFromSliceError),
ArrayLengthError,
}
impl From<TryFromSliceError> for NetworkConvertError {
fn from(value: TryFromSliceError) -> Self {
Self::FromSliceError(value)
}
}
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct Address(SocketAddr); pub struct Address(SocketAddr);
@ -79,25 +92,24 @@ impl From<Address> for Vec<u8> {
} }
impl TryFrom<Vec<u8>> for Address { impl TryFrom<Vec<u8>> for Address {
type Error = TryFromSliceError; type Error = NetworkConvertError;
fn try_from(value: Vec<u8>) -> std::result::Result<Self, Self::Error> { fn try_from(mut value: Vec<u8>) -> std::result::Result<Self, Self::Error> {
const PORT_SIZE: usize = 2; const PORT_SIZE: usize = 2;
if value.len() < PORT_SIZE { if value.len() < PORT_SIZE {
todo!(); return Err(NetworkConvertError::ArrayLengthError);
} }
let mut bytes = value.clone();
let port = u16::from_le_bytes(TryInto::<[u8; PORT_SIZE]>::try_into( let port = u16::from_le_bytes(TryInto::<[u8; PORT_SIZE]>::try_into(
bytes.split_off(bytes.len() - PORT_SIZE).as_slice(), value.split_off(value.len() - PORT_SIZE).as_slice(),
)?); )?);
let addr = if let Ok(bytes) = let addr = if let Ok(value) =
TryInto::<[u8; Ipv4Addr::BITS as usize / 8]>::try_into(bytes.as_slice()) TryInto::<[u8; Ipv4Addr::BITS as usize / 8]>::try_into(value.as_slice())
{ {
SocketAddr::from((bytes, port)) SocketAddr::from((value, port))
} else { } else {
SocketAddr::from(( SocketAddr::from((
TryInto::<[u8; Ipv6Addr::BITS as usize / 8]>::try_into(bytes.as_slice())?, TryInto::<[u8; Ipv6Addr::BITS as usize / 8]>::try_into(value.as_slice())?,
port, port,
)) ))
}; };

View file

@ -34,14 +34,14 @@ impl NetworkReceive {
} }
/// Non-blocking iterator /// Non-blocking iterator
pub fn iter(&self) -> Iter { pub fn iter<'a>(&'a self) -> Iter<'a> {
Iter(self.0.clone()) Iter(&self.0)
} }
} }
pub struct Iter(ReceiveQueue); pub struct Iter<'a>(&'a ReceiveQueue);
impl Iterator for Iter { impl<'a> Iterator for Iter<'a> {
type Item = NetworkMessage; type Item = NetworkMessage;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {