rustlings/exercises/15_traits/traits4.rs

36 lines
798 B
Rust
Raw Normal View History

2024-05-22 14:04:12 +01:00
trait Licensed {
2022-02-25 16:41:10 +00:00
fn licensing_info(&self) -> String {
2024-06-27 11:23:33 +01:00
"Default license".to_string()
2022-02-25 16:41:10 +00:00
}
}
2024-06-27 11:23:33 +01:00
struct SomeSoftware;
struct OtherSoftware;
2022-02-25 16:41:10 +00:00
impl Licensed for SomeSoftware {}
impl Licensed for OtherSoftware {}
2024-06-27 11:23:33 +01:00
// TODO: Fix the compiler error by only changing the signature of this function.
fn compare_license_types(software1: ???, software2: ???) -> bool {
software1.licensing_info() == software2.licensing_info()
2022-02-25 16:41:10 +00:00
}
fn main() {
// You can optionally experiment here.
}
2022-02-25 16:41:10 +00:00
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn compare_license_information() {
2024-06-27 11:23:33 +01:00
assert!(compare_license_types(SomeSoftware, OtherSoftware));
2022-02-25 16:41:10 +00:00
}
#[test]
fn compare_license_information_backwards() {
2024-06-27 11:23:33 +01:00
assert!(compare_license_types(OtherSoftware, SomeSoftware));
2022-02-25 16:41:10 +00:00
}
}