Browse Source

Suppress warnings.

main
Titouan Rigoudy 2 years ago
parent
commit
2e4a7c1472
2 changed files with 26 additions and 8 deletions
  1. +19
    -2
      client/src/server/context.rs
  2. +7
    -6
      client/src/server/login.rs

+ 19
- 2
client/src/server/context.rs View File

@ -1,6 +1,5 @@
use std::mem;
use anyhow::anyhow;
use solstice_proto::ServerRequest;
use thiserror::Error;
use tokio::sync::mpsc::Sender;
@ -22,6 +21,9 @@ pub struct ServerLoggedInContext {
// Immutable, see accessor methods.
user_name: String,
// TODO: Remove annotation.
#[allow(dead_code)]
motd: String,
}
@ -49,17 +51,21 @@ impl ServerLoggedInContext {
request_tx,
}
}
/// The user name with which we logged in.
#[cfg(test)]
pub fn user_name(&self) -> &str {
&self.user_name
}
/// The message of the day sent by the server when we logged in.
#[cfg(test)]
pub fn motd(&self) -> &str {
&self.motd
}
/// Records that we have logged out.
#[cfg(test)]
pub fn logout(self) -> ServerLoggedOutContext {
ServerLoggedOutContext {
user_name: self.user_name,
@ -79,6 +85,7 @@ pub struct ServerLoggedOutContext {
}
/// Information provided upon a successful login.
#[allow(dead_code)]
pub struct ServerLoginInfo {
/// The message of the day sent by the server when we logged in.
pub motd: String,
@ -89,22 +96,26 @@ pub struct ServerLoginInfo {
impl ServerLoggedOutContext {
/// The user name with which we will attempt or have attempted to log in.
#[cfg(test)]
pub fn user_name(&self) -> &str {
&self.user_name
}
/// The error received during the last login attempt, if any.
/// `None` if we have never attempted to log in.
#[cfg(test)]
pub fn error(&self) -> Option<&str> {
self.error.as_deref()
}
/// Records that we failed to log in, and the server sent us the given error.
#[allow(dead_code)]
pub fn set_error(&mut self, error: String) {
self.error = Some(error)
}
/// Records that we logged in successfully.
#[allow(dead_code)]
pub fn login(self, info: ServerLoginInfo) -> ServerLoggedInContext {
ServerLoggedInContext {
user_name: self.user_name,
@ -120,6 +131,7 @@ impl ServerLoggedOutContext {
#[derive(Debug)]
pub enum ServerContext {
/// We are logged out of the server.
#[allow(dead_code)]
LoggedOut(ServerLoggedOutContext),
/// We are logged in to the server.
@ -147,6 +159,7 @@ pub struct ServerLoggedInError {
impl ServerContext {
/// Constructs a new logged out context with the given user name.
#[cfg(test)]
pub fn new(user_name: String) -> Self {
Self::LoggedOut(ServerLoggedOutContext {
user_name,
@ -155,6 +168,7 @@ impl ServerContext {
}
/// Attempts to record a successful login. Fails if we are already logged in.
#[allow(dead_code)]
pub fn login(
&mut self,
info: ServerLoginInfo,
@ -182,6 +196,7 @@ impl ServerContext {
}
/// Attempts to record that we logged out. Fails if we are not logged in.
#[cfg(test)]
pub fn logout(&mut self) -> Result<(), ServerLoggedOutError> {
if let Self::LoggedOut(context) = self {
return Err(ServerLoggedOutError {
@ -192,7 +207,7 @@ impl ServerContext {
// See `mem::replace()` call in `login()`.
let old_self = mem::replace(self, Self::new(String::new()));
let context = match old_self {
Self::LoggedOut(context) => unreachable!(),
Self::LoggedOut(_context) => unreachable!(),
Self::LoggedIn(context) => context,
};
@ -201,6 +216,7 @@ impl ServerContext {
}
/// Returns a reference to the logged in context.
#[allow(dead_code)]
pub fn logged_in(
&mut self,
) -> Result<&mut ServerLoggedInContext, ServerLoggedOutError> {
@ -213,6 +229,7 @@ impl ServerContext {
}
/// Returns a reference to the logged out context.
#[allow(dead_code)]
pub fn logged_out(
&mut self,
) -> Result<&mut ServerLoggedOutContext, ServerLoggedInError> {


+ 7
- 6
client/src/server/login.rs View File

@ -26,6 +26,7 @@ pub enum LoginStatus {
Failure(String),
}
#[allow(dead_code)]
pub enum LoginEvent {
Success(String),
Failure(String),
@ -36,24 +37,24 @@ pub enum LoginEvent {
pub struct LoginEventHandler {}
fn handle_login_success(
context: &mut Context,
motd: String,
_context: &mut Context,
_motd: String,
) -> anyhow::Result<()> {
bail!("unimplemented")
}
fn handle_login_failure(
context: &mut Context,
error: String,
_context: &mut Context,
_error: String,
) -> anyhow::Result<()> {
bail!("unimplemented")
}
fn handle_disconnected(context: &mut Context) -> anyhow::Result<()> {
fn handle_disconnected(_context: &mut Context) -> anyhow::Result<()> {
bail!("unimplemented")
}
fn handle_status_request(context: &mut Context) -> anyhow::Result<()> {
fn handle_status_request(_context: &mut Context) -> anyhow::Result<()> {
bail!("unimplemented")
}


Loading…
Cancel
Save