упр.02 задача 1
- Краен срок:
- 22.10.2025 23:59
- Точки:
- 1
Срокът за предаване на решения е отминал
// Include the solution source in the same file, so we
// don't have to worry about item visibility.
// Please don't use `include!` in real code, this is a hack
// around the checking system.
include!{ "../src/lib.rs" }
#[test]
fn test_basic() {
assert_eq!(duplicate_i32(10), (10, 10));
assert_eq!(duplicate_string("Здравей".to_string()), ("Здравей".to_string(), "Здравей".to_string()));
}
fn duplicate_i32(x: i32) -> (i32, i32) {
// реализирай тази функция
}
fn duplicate_string(s: String) -> (String, String) {
// реализирай тази функция
}
fn main() {
let a = 10;
let (a1, a2) = duplicate_i32(a);
println!("a1 = {}, a2 = {}, original a = {}", a1, a2, a);
let s = String::from("Здравей");
let (s1, s2) = duplicate_string(s);
println!("s1 = {}, s2 = {}", s1, s2);
}
- a) Имплементирай
duplicate_i32иduplicate_string. - b) Обясни защо в случая с
i32е възможно да използвамеxслед извикване, но не можем да използвамеsследduplicate_string. - c) Какво става, ако
duplicate_stringвърне(s, s)— защо компилаторът го забранява?
П.С. игнорирайте линка с указания за домашни - добавя се автоматично и не е актуален в случая.
Задължително прочетете (или си припомнете): Указания за предаване на домашни
Погрижете се решението ви да се компилира с базовия тест:
// Include the solution source in the same file, so we
// don't have to worry about item visibility.
// Please don't use `include!` in real code, this is a hack
// around the checking system.
include!{ "../src/lib.rs" }
#[test]
fn test_basic() {
assert_eq!(duplicate_i32(10), (10, 10));
assert_eq!(duplicate_string("Здравей".to_string()), ("Здравей".to_string(), "Здравей".to_string()));
}
