Skip to content

Issues with the box_recursion Exercise of rust_tests #163

@BenaliOssama

Description

@BenaliOssama

** Wrong Return Type in last_worker**

Problem:
The instructions require this function signature:

pub fn last_worker(&self) -> Option<(String, Role)>

But the provided solution uses:

pub fn last_worker(&self) -> Option<(String, String)>

This causes a mismatch with the tests, which expect a Role enum, not a String.

Fix:
Implement the Role enum and use it in both the Worker struct and the return type of last_worker.


3. Missing Role Enum

Problem:
Tests expect values like Role::CEO, Role::Manager, and Role::Worker.
The provided solution stores roles as String instead, which is incorrect.

Fix:
Define the Role enum as follows:

#[derive(Debug, PartialEq)]
pub enum Role {
    CEO,
    Manager,
    Worker,
}

impl From<&str> for Role {
    fn from(s: &str) -> Self {
        match s {
            "CEO" => Role::CEO,
            "Manager" => Role::Manager,
            _ => Role::Worker,
        }
    }
}

Then update the Worker struct to use Role:

pub struct Worker {
    pub role: Role,
    pub name: String,
    pub next: Link,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions