Coming from javascript/python I'm used to the idea of classes but am struggling to understand the difference between a Struct and an Enum.
For example I can define a 'class' with behaviours in similar ways
struct
// Defines the StartListen class
pub struct StartListen {
socket: SocketAddr,
listener: TcpListener,
}
// Implementation for StartListen class
impl StartListen {
pub async fn new(socket: SocketAddr) -> Result<StartListen, StartListenError> {
println!("Attempting to listen");
enum
// Defines the types of messages to expect
#[derive(Debug)]
pub enum RequestType {
RequestWork {
request_message: String,
parameter: String,
sender_timestamp: String,
},
CloseConnection {
initial_timestamp: String,
final_timestamp: String,
},
Invalid(String),
}
// The Implementation for the RequestType Enum
impl RequestType{
fn from_message_string(message_string: &str, pool: Arc<Pool>) -> RequestType {
println!("Checking request type...");
I can define methods using enums, which is most similar to what I assume is a class. In what scenario would you use a struct?