netgauze_bmp_service/
lib.rs1use serde::{Deserialize, Serialize};
17
18use netgauze_bmp_pkt::codec::BmpCodecDecoderError;
19use std::{
20 fmt::{Display, Formatter},
21 net::SocketAddr,
22};
23
24pub mod handle;
25pub mod server;
26pub mod transport;
27
28#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Serialize, Deserialize)]
30pub struct AddrInfo {
31 local_socket: SocketAddr,
32 remote_socket: SocketAddr,
33}
34
35impl AddrInfo {
36 pub const fn new(local_socket: SocketAddr, remote_socket: SocketAddr) -> Self {
37 Self {
38 local_socket,
39 remote_socket,
40 }
41 }
42
43 pub const fn local_socket(&self) -> SocketAddr {
44 self.local_socket
45 }
46
47 pub const fn remote_socket(&self) -> SocketAddr {
48 self.remote_socket
49 }
50}
51
52#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
54pub struct TaggedData<T, V> {
55 tag: T,
56 value: V,
57}
58
59impl<T: Copy, V> TaggedData<T, V> {
60 pub const fn new(tag: T, value: V) -> Self {
61 Self { tag, value }
62 }
63
64 pub const fn tag(&self) -> T {
65 self.tag
66 }
67
68 pub const fn value(&self) -> &V {
69 &self.value
70 }
71}
72
73impl Display for TaggedData<AddrInfo, BmpCodecDecoderError> {
74 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
75 write!(f, "{self:?}")
76 }
77}
78
79impl std::error::Error for TaggedData<AddrInfo, BmpCodecDecoderError> {}