Shorten ByteBuf trait bounds everywhere

This commit is contained in:
Igor Katson 2024-08-25 13:29:28 +01:00
parent c7b7dc300f
commit 9d1ef5c35c
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
6 changed files with 35 additions and 27 deletions

View file

@ -1,19 +1,18 @@
use std::{
collections::HashMap,
net::IpAddr,
};
use std::{collections::HashMap, net::IpAddr};
use buffers::ByteBuf;
use buffers::{ByteBuf, ByteBufT};
use bytes::Bytes;
use clone_to_owned::CloneToOwned;
use serde::{Deserialize, Deserializer, Serialize};
use crate::{EXTENDED_UT_METADATA_KEY, EXTENDED_UT_PEX_KEY, MY_EXTENDED_UT_METADATA, MY_EXTENDED_UT_PEX};
use crate::{
EXTENDED_UT_METADATA_KEY, EXTENDED_UT_PEX_KEY, MY_EXTENDED_UT_METADATA, MY_EXTENDED_UT_PEX,
};
use super::PeerExtendedMessageIds;
#[derive(Deserialize, Serialize, Debug, Default)]
pub struct ExtendedHandshake<ByteBuf: Eq + std::hash::Hash> {
pub struct ExtendedHandshake<ByteBuf: ByteBufT> {
#[serde(bound(deserialize = "ByteBuf: From<&'de [u8]>"))]
pub m: HashMap<ByteBuf, u8>,
#[serde(skip_serializing_if = "Option::is_none")]
@ -50,7 +49,7 @@ impl ExtendedHandshake<ByteBuf<'static>> {
impl<'a, ByteBuf> ExtendedHandshake<ByteBuf>
where
ByteBuf: Eq + std::hash::Hash + std::borrow::Borrow<[u8]>,
ByteBuf: ByteBufT,
{
fn get_msgid(&self, msg_type: &'a [u8]) -> Option<u8> {
self.m.get(msg_type).copied()
@ -74,8 +73,8 @@ where
impl<ByteBuf> CloneToOwned for ExtendedHandshake<ByteBuf>
where
ByteBuf: CloneToOwned + Eq + std::hash::Hash,
<ByteBuf as CloneToOwned>::Target: Eq + std::hash::Hash,
ByteBuf: ByteBufT,
<ByteBuf as CloneToOwned>::Target: ByteBufT,
{
type Target = ExtendedHandshake<<ByteBuf as CloneToOwned>::Target>;