I am sorry, but I am so lost that I'm not sure how to frame the question. If you have a suggestion for a better title, please let me know.
I researched type ascription, and found that it is the ability to annotate an expression with the type we want it to have.
I defined the following trait and function. From my limited understanding, I am specifying the type to be u16
:
// src/range.rs
pub struct Range {
pub min: u16,
pub max: u16,
pub current: u16
}
impl Range {
pub fn new(min: u16, max: u16, current: u16) -> Self {
Range{ min, max, current }
}
Next, I wanted to test new()
inside my integration_tests:
// tests/integration_tests.rs
use confine::range::Range;
#[test]
fn new_confine() {
assert_eq!(Range{min: 1, max: 6, cursor: 1}, Range::new(min: 1, max: 6, cursor: 1));
Why is the compiler confused by the type when I specifically defined the struct to be u16? I tried explicitly writing 1u16
too.
I am receiving the following error:
error: expected type, found `1`
--> tests/integration_test.rs:5:70
|
5 | assert_eq!(Confine{min: 1, max: 6, cursor: 1}, Confine::new(min: 1, max: 6, cursor: 1));
| - ^ expected type
| |
| tried to parse a type due to this type ascription
|