After defining a struct like so:
pub struct Vers {
pub bk: String,
pub ch: u32,
pub vs: u32,
pub a: Option<Vec<i32>>,
pub b: Option<Vec<i32>>,
}
And creating an instance like so:
let v1 = Vers {
bk: String::from("Canticum"),
ch: 1,
vs: 1,
a: Some(vec![71, 73, 71, 00]),
b: None,
};
I need a function to extract the last, or first element of the vector, without taking ownership.
I started with the one below, but this, of course, takes ownership. And, probably, it can be done more effectively. So any help is welcome.
fn last_acc(v: Option<Vec<i32>>) {
let vs = v.unwrap();
let lst = vs.last();
println!("{:?}", lst.unwrap());
}