Skip to content

Commit 22212a7

Browse files
committed
Question improvements
1 parent 38d55b5 commit 22212a7

File tree

4 files changed

+21
-50
lines changed

4 files changed

+21
-50
lines changed

questions/q001.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ question: |-
1010
1111
What will this Rust code print?
1212
answers:
13-
- '[2, 3, 4]'
14-
- '[2, 3, 4, 5]'
13+
- '`[2, 3, 4]`'
14+
- '`[2, 3, 4, 5]`'
1515
- Compilation error
1616
- Runtime panic
1717
correct_answer: 2

questions/q002.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ question: |-
1515
1616
What is the output of this code?
1717
answers:
18-
- Some([1, 2, 3])
19-
- Some([4, 5, 6, 7])
20-
- Some([1, 2, 3, 7])
21-
- Some([1, 2, 3, 4, 5, 6, 7])
18+
- '`Some([1, 2, 3])`'
19+
- '`Some([4, 5, 6, 7])`'
20+
- '`Some([1, 2, 3, 7])`'
21+
- '`Some([1, 2, 3, 4, 5, 6, 7])`'
2222
correct_answer: 2
2323
expected_output:
2424
- Some([1, 2, 3, 7])

questions/q222.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
question: |-
22
```rust
3-
// This code simulates a library crate with pub(crate) visibility
4-
// In a real scenario, main.rs would be in a separate crate
5-
3+
// mylib/src/lib.rs
64
mod mylib {
75
pub mod utils {
8-
pub(crate) fn internal_helper() -> i32 { 42 }
9-
pub fn public_helper() -> i32 { 24 }
6+
pub(crate) fn compute_offset() -> i32 { 42 }
7+
pub fn calculate_sum() -> i32 { 24 }
108
}
119
}
10+
```
1211
12+
```rust
13+
// main.rs (separate binary crate)
1314
fn main() {
1415
use mylib::utils;
15-
println!("{}", utils::public_helper());
16-
println!("{}", utils::internal_helper());
16+
println!("{}", utils::calculate_sum());
17+
println!("{}", utils::compute_offset());
1718
}
1819
```
1920
@@ -23,24 +24,23 @@ answers:
2324
- Only the first call works, second fails with "function is private"
2425
- Only the second call works, first fails with "function is private"
2526
- Both calls fail because the `utils` module is not accessible
26-
correct_answer: 0
27+
correct_answer: 1
2728
expected_output:
28-
- '24'
29-
- '42'
29+
- 'private function'
3030
explanation: |-
3131
This question tests understanding of Rust's `pub(crate)` visibility modifier and
3232
crate boundaries. The `pub(crate)` modifier makes an item public within the
3333
defining crate but private across crate boundaries.
3434
35-
In this code, both `internal_helper()` (marked `pub(crate)`) and
36-
`public_helper()` (marked `pub`) are defined in the `mylib` module. Since
35+
In this code, both `compute_offset()` (marked `pub(crate)`) and
36+
`calculate_sum()` (marked `pub`) are defined in the `mylib` module. Since
3737
`main()` is in the same crate as the `mylib` module, both functions are
3838
accessible. The `pub(crate)` visibility allows access from anywhere within the
3939
same crate, so both function calls succeed and print "24" then "42".
4040
4141
The key distinction is that if `main.rs` were in a separate crate that depends
42-
on `mylib` as an external library, then only `public_helper()` would be
43-
accessible. The `internal_helper()` function would be private across the crate
42+
on `mylib` as an external library, then only `calculate_sum()` would be
43+
accessible. The `compute_offset()` function would be private across the crate
4444
boundary, resulting in a compilation error.
4545
4646
The key takeaway is that `pub(crate)` creates crate-local public visibility -

questions/q237.yaml

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,4 @@
11
question: |-
2-
```rust
3-
// This represents what a procedural macro might generate
4-
// Note: proc_macro is only available in proc-macro crates,
5-
// so we're showing a conceptual example here
6-
7-
// Simulating a derive macro expansion
8-
// #[some_derive_macro]
9-
struct User {
10-
name: String,
11-
age: u32,
12-
}
13-
14-
// What the macro might expand to:
15-
impl User {
16-
fn validate(&self) -> bool {
17-
!self.name.is_empty() && self.age > 0
18-
}
19-
}
20-
21-
fn main() {
22-
let user = User {
23-
name: "Alice".to_string(),
24-
age: 30,
25-
};
26-
println!("{}", user.validate());
27-
}
28-
```
29-
302
What is the key difference between declarative macros (`macro_rules!`) and
313
procedural macros?
324
answers:
@@ -35,8 +7,7 @@ answers:
357
- Procedural macros operate on token streams and can run arbitrary Rust code at compile time
368
- Declarative macros are more powerful and can generate more complex code
379
correct_answer: 2
38-
expected_output:
39-
- 'true'
10+
expected_output: []
4011
explanation: |-
4112
This question tests understanding of the fundamental differences between Rust's
4213
two macro systems: declarative macros (`macro_rules!`) and procedural macros.

0 commit comments

Comments
 (0)