2024-06-18 14:32:54 +08:00

49 lines
1.1 KiB
Rust

// traits4.rs
//
// 您的任務是替換 '??' 部分以使代碼通過編譯。
//
// 除了標記的行外,不要更改任何行。
//
// 執行 `rustlings hint traits4` 或使用 `hint` watch 子命令來獲取提示。
// I AM NOT DONE
pub trait Licensed {
fn licensing_info(&self) -> String {
"some information".to_string()
}
}
struct SomeSoftware {}
struct OtherSoftware {}
impl Licensed for SomeSoftware {}
impl Licensed for OtherSoftware {}
// 您只能更改下一行
fn compare_license_types(software: ??, software_two: ??) -> bool {
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));
}
}