tokio_zmq/socket/types.rs
1/*
2 * This file is part of Tokio ZMQ.
3 *
4 * Copyright © 2018 Riley Trautman
5 *
6 * Tokio ZMQ is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Tokio ZMQ is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Tokio ZMQ. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20//! This module defines all the socket wrapper types that can be used with Tokio.
21
22use async_zmq_derive::SocketWrapper;
23use zmq::SocketType::{self, DEALER, PAIR, PUB, PULL, PUSH, REP, REQ, ROUTER, SUB, XPUB, XSUB};
24
25use crate::{async_types::EventedFile, socket::Socket};
26
27// needed for derive
28type RawSocket = (zmq::Socket, EventedFile);
29
30/* -------------------------------------------------------------------------- */
31
32/// The DEALER `SocketType` wrapper type.
33///
34/// Dealer implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
35#[derive(Debug, SocketWrapper)]
36#[stream]
37#[sink]
38pub struct Dealer {
39 pub(crate) inner: Socket,
40}
41
42/* -------------------------------------------------------------------------- */
43
44/// The PAIR `SocketType` wrapper type.
45///
46/// Pair implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
47#[derive(Debug, SocketWrapper)]
48#[stream]
49#[sink]
50pub struct Pair {
51 pub(crate) inner: Socket,
52}
53
54/* -------------------------------------------------------------------------- */
55
56/// The PUB `SocketType` wrapper type
57///
58/// Pub implements `SinkSocket`.
59#[derive(Debug, SocketWrapper)]
60#[sink]
61pub struct Pub {
62 pub(crate) inner: Socket,
63}
64
65/* -------------------------------------------------------------------------- */
66
67/// The PULL `SocketType` wrapper type
68///
69/// Pull implements `StreamSocket`, and has an associated controlled variant.
70#[derive(Debug, SocketWrapper)]
71#[stream]
72pub struct Pull {
73 pub(crate) inner: Socket,
74}
75
76/* -------------------------------------------------------------------------- */
77
78/// The PUSH `SocketType` wrapper type
79///
80/// Push implements `SinkSocket`.
81#[derive(Debug, SocketWrapper)]
82#[sink]
83pub struct Push {
84 pub(crate) inner: Socket,
85}
86
87/* -------------------------------------------------------------------------- */
88
89/// The REP `SocketType` wrapper type
90///
91/// Rep implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
92#[derive(Debug, SocketWrapper)]
93#[stream]
94#[sink]
95pub struct Rep {
96 pub(crate) inner: Socket,
97}
98
99/* -------------------------------------------------------------------------- */
100
101/// The REQ `SocketType` wrapper type
102///
103/// Req implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
104#[derive(Debug, SocketWrapper)]
105#[stream]
106#[sink]
107pub struct Req {
108 pub(crate) inner: Socket,
109}
110
111/* -------------------------------------------------------------------------- */
112
113/// The ROUTER `SocketType` wrapper type
114///
115/// Router implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
116#[derive(Debug, SocketWrapper)]
117#[stream]
118#[sink]
119pub struct Router {
120 pub(crate) inner: Socket,
121}
122
123/* -------------------------------------------------------------------------- */
124
125/// The SUB `SocketType` wrapper type
126///
127/// Sub implements `StreamSocket`, and has an associated controlled variant.
128#[derive(Debug, SocketWrapper)]
129#[stream]
130pub struct Sub {
131 pub(crate) inner: Socket,
132}
133
134/* -------------------------------------------------------------------------- */
135
136/// The XPUB `SocketType` wrapper type
137///
138/// Xpub implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
139#[derive(Debug, SocketWrapper)]
140#[stream]
141#[sink]
142pub struct Xpub {
143 pub(crate) inner: Socket,
144}
145
146/* -------------------------------------------------------------------------- */
147
148/// The XSUB `SocketType` wrapper type
149///
150/// Xsub implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
151#[derive(Debug, SocketWrapper)]
152#[stream]
153#[sink]
154pub struct Xsub {
155 pub(crate) inner: Socket,
156}