Solve some warnings
This commit is contained in:
parent
80a6582ce5
commit
478cb20555
2 changed files with 22 additions and 22 deletions
|
|
@ -123,6 +123,9 @@ impl Connected {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The warning about enum variant sizes shouldn't matter since a connection will
|
||||||
|
// spend most its time in the Connected state anyways.
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum State {
|
pub enum State {
|
||||||
Connecting,
|
Connecting,
|
||||||
Connected(Connected),
|
Connected(Connected),
|
||||||
|
|
@ -186,7 +189,7 @@ impl CoveConn {
|
||||||
if let Some(connected) = state.connected_mut() {
|
if let Some(connected) = state.connected_mut() {
|
||||||
if let Status::IdRequired(_) = connected.status {
|
if let Status::IdRequired(_) = connected.status {
|
||||||
connected.status = Status::Identifying;
|
connected.status = Status::Identifying;
|
||||||
self.ev_tx.send(Event::StateChanged);
|
let _ = self.ev_tx.send(Event::StateChanged);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -222,13 +225,13 @@ impl CoveConnMt {
|
||||||
Ok(conn) => conn,
|
Ok(conn) => conn,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
*self.conn.state.lock().await = State::Stopped;
|
*self.conn.state.lock().await = State::Stopped;
|
||||||
self.conn.ev_tx.send(Event::StateChanged);
|
let _ = self.conn.ev_tx.send(Event::StateChanged);
|
||||||
return Err(Error::CouldNotConnect(e));
|
return Err(Error::CouldNotConnect(e));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
*self.conn.state.lock().await = State::Connected(Connected::new(tx, self.timeout));
|
*self.conn.state.lock().await = State::Connected(Connected::new(tx, self.timeout));
|
||||||
self.conn.ev_tx.send(Event::StateChanged);
|
let _ = self.conn.ev_tx.send(Event::StateChanged);
|
||||||
|
|
||||||
tokio::spawn(Self::join_room(self.conn.clone(), self.room));
|
tokio::spawn(Self::join_room(self.conn.clone(), self.room));
|
||||||
let result = tokio::select! {
|
let result = tokio::select! {
|
||||||
|
|
@ -237,7 +240,7 @@ impl CoveConnMt {
|
||||||
};
|
};
|
||||||
|
|
||||||
*self.conn.state.lock().await = State::Stopped;
|
*self.conn.state.lock().await = State::Stopped;
|
||||||
self.conn.ev_tx.send(Event::StateChanged);
|
let _ = self.conn.ev_tx.send(Event::StateChanged);
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
@ -252,16 +255,14 @@ impl CoveConnMt {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn join_room(conn: CoveConn, name: String) -> Result<(), Error> {
|
async fn join_room(conn: CoveConn, name: String) -> Result<(), Error> {
|
||||||
let reply: RoomRpl = conn.cmd(RoomCmd { name }).await?;
|
let _: RoomRpl = conn.cmd(RoomCmd { name }).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn recv(conn: &CoveConn, mut rx: ConnRx) -> Result<(), Error> {
|
async fn recv(conn: &CoveConn, mut rx: ConnRx) -> Result<(), Error> {
|
||||||
while let Some(packet) = rx.recv().await? {
|
while let Some(packet) = rx.recv().await? {
|
||||||
match packet {
|
match packet {
|
||||||
Packet::Cmd { id, cmd } => {
|
Packet::Cmd { .. } => {} // Ignore commands, the server shouldn't send any
|
||||||
// Ignore commands as the server doesn't send them.
|
|
||||||
}
|
|
||||||
Packet::Rpl { id, rpl } => Self::on_rpl(conn, id, rpl).await?,
|
Packet::Rpl { id, rpl } => Self::on_rpl(conn, id, rpl).await?,
|
||||||
Packet::Ntf { ntf } => Self::on_ntf(conn, ntf).await?,
|
Packet::Ntf { ntf } => Self::on_ntf(conn, ntf).await?,
|
||||||
}
|
}
|
||||||
|
|
@ -279,18 +280,18 @@ impl CoveConnMt {
|
||||||
match &rpl {
|
match &rpl {
|
||||||
Rpl::Room(RoomRpl::Success) => {
|
Rpl::Room(RoomRpl::Success) => {
|
||||||
connected.status = Status::IdRequired(None);
|
connected.status = Status::IdRequired(None);
|
||||||
conn.ev_tx.send(Event::IdentificationRequired);
|
let _ = conn.ev_tx.send(Event::IdentificationRequired);
|
||||||
}
|
}
|
||||||
Rpl::Room(RoomRpl::InvalidRoom { reason }) => {
|
Rpl::Room(RoomRpl::InvalidRoom { reason }) => {
|
||||||
return Err(Error::InvalidRoom(reason.clone()))
|
return Err(Error::InvalidRoom(reason.clone()))
|
||||||
}
|
}
|
||||||
Rpl::Identify(IdentifyRpl::Success { you, others, .. }) => {
|
Rpl::Identify(IdentifyRpl::Success { you, others, .. }) => {
|
||||||
connected.status = Status::Present(Present::new(you, others));
|
connected.status = Status::Present(Present::new(you, others));
|
||||||
conn.ev_tx.send(Event::StateChanged);
|
let _ = conn.ev_tx.send(Event::StateChanged);
|
||||||
}
|
}
|
||||||
Rpl::Identify(IdentifyRpl::InvalidNick { reason }) => {
|
Rpl::Identify(IdentifyRpl::InvalidNick { reason }) => {
|
||||||
connected.status = Status::IdRequired(Some(reason.clone()));
|
connected.status = Status::IdRequired(Some(reason.clone()));
|
||||||
conn.ev_tx.send(Event::IdentificationRequired);
|
let _ = conn.ev_tx.send(Event::IdentificationRequired);
|
||||||
}
|
}
|
||||||
Rpl::Identify(IdentifyRpl::InvalidIdentity { reason }) => {
|
Rpl::Identify(IdentifyRpl::InvalidIdentity { reason }) => {
|
||||||
return Err(Error::InvalidIdentity(reason.clone()))
|
return Err(Error::InvalidIdentity(reason.clone()))
|
||||||
|
|
@ -298,18 +299,18 @@ impl CoveConnMt {
|
||||||
Rpl::Nick(NickRpl::Success { you }) => {
|
Rpl::Nick(NickRpl::Success { you }) => {
|
||||||
if let Some(present) = connected.status.present_mut() {
|
if let Some(present) = connected.status.present_mut() {
|
||||||
present.update_session(you);
|
present.update_session(you);
|
||||||
conn.ev_tx.send(Event::StateChanged);
|
let _ = conn.ev_tx.send(Event::StateChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Rpl::Nick(NickRpl::InvalidNick { reason }) => {}
|
Rpl::Nick(NickRpl::InvalidNick { reason: _ }) => {}
|
||||||
Rpl::Send(SendRpl::Success { message }) => {
|
Rpl::Send(SendRpl::Success { message }) => {
|
||||||
// TODO Add message to message store or send an event
|
// TODO Add message to message store or send an event
|
||||||
}
|
}
|
||||||
Rpl::Send(SendRpl::InvalidContent { reason }) => {}
|
Rpl::Send(SendRpl::InvalidContent { reason: _ }) => {}
|
||||||
Rpl::Who(WhoRpl { you, others }) => {
|
Rpl::Who(WhoRpl { you, others }) => {
|
||||||
if let Some(present) = connected.status.present_mut() {
|
if let Some(present) = connected.status.present_mut() {
|
||||||
present.update(you, others);
|
present.update(you, others);
|
||||||
conn.ev_tx.send(Event::StateChanged);
|
let _ = conn.ev_tx.send(Event::StateChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -330,19 +331,19 @@ impl CoveConnMt {
|
||||||
Ntf::Join(JoinNtf { who }) => {
|
Ntf::Join(JoinNtf { who }) => {
|
||||||
if let Some(present) = connected.status.present_mut() {
|
if let Some(present) = connected.status.present_mut() {
|
||||||
present.join(who);
|
present.join(who);
|
||||||
conn.ev_tx.send(Event::StateChanged);
|
let _ = conn.ev_tx.send(Event::StateChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ntf::Nick(NickNtf { who }) => {
|
Ntf::Nick(NickNtf { who }) => {
|
||||||
if let Some(present) = connected.status.present_mut() {
|
if let Some(present) = connected.status.present_mut() {
|
||||||
present.nick(who);
|
present.nick(who);
|
||||||
conn.ev_tx.send(Event::StateChanged);
|
let _ = conn.ev_tx.send(Event::StateChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ntf::Part(PartNtf { who }) => {
|
Ntf::Part(PartNtf { who }) => {
|
||||||
if let Some(present) = connected.status.present_mut() {
|
if let Some(present) = connected.status.present_mut() {
|
||||||
present.part(who);
|
present.part(who);
|
||||||
conn.ev_tx.send(Event::StateChanged);
|
let _ = conn.ev_tx.send(Event::StateChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ntf::Send(SendNtf { message }) => {
|
Ntf::Send(SendNtf { message }) => {
|
||||||
|
|
@ -362,7 +363,7 @@ pub async fn new(
|
||||||
) -> (CoveConn, CoveConnMt) {
|
) -> (CoveConn, CoveConnMt) {
|
||||||
let conn = CoveConn {
|
let conn = CoveConn {
|
||||||
state: Arc::new(Mutex::new(State::Connecting)),
|
state: Arc::new(Mutex::new(State::Connecting)),
|
||||||
ev_tx: ev_tx.clone(),
|
ev_tx,
|
||||||
};
|
};
|
||||||
let mt = CoveConnMt {
|
let mt = CoveConnMt {
|
||||||
url,
|
url,
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ impl ConnConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CoveRoom {
|
pub struct CoveRoom {
|
||||||
name: String,
|
|
||||||
conn: Arc<Mutex<CoveConn>>,
|
conn: Arc<Mutex<CoveConn>>,
|
||||||
/// Once this is dropped, all other room-related tasks, connections and
|
/// Once this is dropped, all other room-related tasks, connections and
|
||||||
/// values are cleaned up.
|
/// values are cleaned up. It is never used to send actual values.
|
||||||
|
#[allow(dead_code)]
|
||||||
dead_mans_switch: Sender<Never>,
|
dead_mans_switch: Sender<Never>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,7 +60,6 @@ impl CoveRoom {
|
||||||
let (conn, mt) = conf.new_conn().await;
|
let (conn, mt) = conf.new_conn().await;
|
||||||
|
|
||||||
let room = Self {
|
let room = Self {
|
||||||
name: name.clone(),
|
|
||||||
conn: Arc::new(Mutex::new(conn)),
|
conn: Arc::new(Mutex::new(conn)),
|
||||||
dead_mans_switch: tx,
|
dead_mans_switch: tx,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue