2022-02-25 16:41:10 +00:00
|
|
|
// traits4.rs
|
|
|
|
//
|
|
|
|
// Your task is to replace the '??' sections so the code compiles.
|
2023-05-29 17:39:08 +00:00
|
|
|
//
|
2022-07-16 17:51:50 +00:00
|
|
|
// Don't change any line other than the marked one.
|
2023-05-29 17:39:08 +00:00
|
|
|
//
|
|
|
|
// Execute `rustlings hint traits4` or use the `hint` watch subcommand for a
|
|
|
|
// hint.
|
2022-02-25 16:41:10 +00:00
|
|
|
|
|
|
|
pub trait Licensed {
|
|
|
|
fn licensing_info(&self) -> String {
|
|
|
|
"some information".to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SomeSoftware {}
|
|
|
|
|
|
|
|
struct OtherSoftware {}
|
|
|
|
|
|
|
|
impl Licensed for SomeSoftware {}
|
|
|
|
impl Licensed for OtherSoftware {}
|
|
|
|
|
2022-07-16 17:51:50 +00:00
|
|
|
// YOU MAY ONLY CHANGE THE NEXT LINE
|
2023-09-10 16:38:07 +00:00
|
|
|
fn compare_license_types(software: impl Licensed, software_two: impl Licensed) -> bool {
|
2022-02-25 16:41:10 +00:00
|
|
|
software.licensing_info() == software_two.licensing_info()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compare_license_information() {
|
|
|
|
let some_software = SomeSoftware {};
|
|
|
|
let other_software = OtherSoftware {};
|
|
|
|
|
|
|
|
assert!(compare_license_types(some_software, other_software));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compare_license_information_backwards() {
|
|
|
|
let some_software = SomeSoftware {};
|
|
|
|
let other_software = OtherSoftware {};
|
|
|
|
|
|
|
|
assert!(compare_license_types(other_software, some_software));
|
|
|
|
}
|
|
|
|
}
|