Hello
Why do I get mismatched types?
error[E0308]: mismatched types
--> src/c.rs:18:16
|
18 | return C{a: a, b: b};
| ^^^^^^^^^^^^^ expected (), found struct `c::C`
|
= note: expected type `()`
found type `c::C`
error: aborting due to previous error
The code contain files in the src folder.
Thanks
A.rs:
pub struct A {
a: i16
}
impl A {
pub fn new() -> A {
return A{a:0};
}
pub fn add(&self, i:i16) {
self.a += i;
}
pub fn get(&self) -> i16 {
return self.a;
}
}
B.rs:
pub struct B {
b: i16
}
impl B {
pub fn new() -> B {
return B{b:0};
}
pub fn add(&self, i:i16) {
self.b += i;
}
pub fn get(&self) -> i16 {
return self.b;
}
}
C.rs:
use super::a::A;
use super::b::B;
pub struct C {
a: A,
b: B
}
impl C {
pub fn new() {
let a = A::new();
let b = B::new();
return C{a: a, b: b};
}
pub fn add(&self, i:i16) {
self.a.add(i);
self.b.add(i);
}
pub fn get(&self) -> i16 {
return self.a.get() + self.b.get();
}
}