You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1.5 KiB

copy

Instructions

Create the following functions. The objective is to know how ownership works with different types.

  • nbr_function returns a tuple:
    • with the original value.
    • the exponential function of the value.
    • and the natural logarithm of the absolute value.
  • str_function returns a tuple:
    • with the original value.
    • and the exponential function of each value as a string (see the example).
  • vec_function returns a tuple:
    • with the original value.
    • and the natural logarithm of each absolute value.

Expected functions

pub fn nbr_function(c: i32) -> (i32, f64, f64) {
}

pub fn str_function(a: String) -> (String, String) {
}

pub fn vec_function(b: Vec<i32>) -> (Vec<i32>, Vec<f64>) {
}

Usage

Here is a possible program to test your function :

use copy::*;

fn main() {
    let a: i32 = 0;
    let b = String::from("1 2 4 5 6");
    let c = vec![1, 2, 4, 5];

    println!("{:?}", nbr_function(a));
    println!("{:?}", str_function(b));
    println!("{:?}", vec_function(c));
}

And its output:

$ cargo run
(0, 1.0, -inf)
("1 2 4 5 6", "2.718281828459045 7.38905609893065 54.598150033144236 148.4131591025766 403.4287934927351")
([1, 2, 4, 5], [0.0, 0.6931471805599453, 1.3862943611198906, 1.6094379124341003])
$

Notions