Skip to content

chore: St registry assignment#14

Open
RichoKD wants to merge 4 commits intoBlockheaderWeb3-Community:st-registry-assignmentfrom
RichoKD:st-registry-assignment
Open

chore: St registry assignment#14
RichoKD wants to merge 4 commits intoBlockheaderWeb3-Community:st-registry-assignmentfrom
RichoKD:st-registry-assignment

Conversation

@RichoKD
Copy link

@RichoKD RichoKD commented Aug 15, 2024

Implemented CLI state machine for student and course management

added ex_1.rs file to student_registry_project which takes user input to alter flow state and implement course management functions

Copy link
Contributor

@Abeeujah Abeeujah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Job, The CLI state machine is a great way to demonstrate your rust skills, consider implementing the prescribed changes.

// }
fn get_courses(rust_cohort: &mut StudentRegistry) -> u32 {
print!("{:#?}", rust_cohort.course_registry);
io::stdout().flush().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to use println! macro, if newline behavior is the default.


print!("1. Add student\n2. Get student\n3.Enroll student in course\n4.Return\n");
io::stdout().flush().unwrap();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider implementing utility functions to parse user inputs. This will help keep the code modular and DRY.

.expect("Failed to read line");
let sex = sex.trim().parse::<u8>().unwrap();

if sex == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let sex = if sex == 1 { Sex::Male } else {Sex::Female };
Initialise the student.

let mut id = String::new();
io::stdin().read_line(&mut id).expect("Failed to read line");
let id = id.trim().parse::<u32>().unwrap();
let student = rust_cohort.get_student_by_id(id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In critical mission applications, Consider handling cases where value could be Some or None. This function returns an Option

id: course_id,
name: _name,
capacity: _capacity,
enrolled_student_ids: Vec::new(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vec::with_capacity()

.trim()
.parse::<i32>()
.expect("Invalid input. Please enter a number.");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a match expression.

@RichoKD RichoKD marked this pull request as draft August 17, 2024 13:34
@RichoKD RichoKD changed the title St registry assignment chore: St registry assignment Aug 18, 2024
@RichoKD RichoKD marked this pull request as ready for review August 18, 2024 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants