Bora
September 27, 2022, 6:13am
1
What does this lines of code mean?
pub trait CacheableItem: Clone + Default + fmt::Debug + Decodable + Encodable {
type Address: AsRef<[u8]> + Clone + fmt::Debug + Eq + Hash;
fn is_null(&self) -> bool;
}
impl<T: Summary + Clone + Default > Controller<T>
{
fn is_null(&self) -> bool
{
// Other codes
}
}
Can you be a little more specific? There are a lot of different language features being used there, and not a lot of context for what the actual goal is.
If you don't know where to start The Rust Book may be a good choice for learning more.
Bora
September 27, 2022, 7:09am
3
just wondering what that means
<T: Debug + Clone>
What does he mean by "Debug + Clone" in this line?
Also, could a struct or enumeration be used instead of using trait in this line, for example:
struct Point {
x: i32,
y: i32,
}
<T: Point>
OR
<T: Point + Debug + Clone>
<T: Debug + Clone>
means roughly "Each time this item is used there will be a concrete type in place of T
, but we don't know anything about that type except that it must implement both Debug
and Clone
"
You can't use a struct there, only traits.
2 Likes
alice
September 27, 2022, 7:24am
5
In the future, please properly format your code:
To format code in this forum you need to surround the code with three backticks (```). For example, typing this...
```
fn main() {
println!()
}
```
...will be rendered as highlighted Rust code, like so:
fn main() {
println!()
}
You can also tell the forum software which language you're using by adding the language after the opening backticks.
```cpp
#include <iostream>
int main() {
std::cout << "Hello World!";
}
```
Will appear with highlighting as:
#include <iostream>
int main(…
I know that some people answer questions that aren't properly formatted, but I certainly don't.
Bora
September 27, 2022, 8:44am
7
Sorry didn't see the formatting option I formatted it now
system
Closed
December 26, 2022, 8:44am
8
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.