Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(const_vec_new)]
- static mut vStrSlc: Vec<&str> = Vec::new();
- static mut vI32: Vec<i32> = Vec::new();
- trait Trait1 {
- fn f1(item: Self);
- fn f2()->Self;
- }
- impl Trait1 for &'static [&'static str] {
- fn f1(items: &'static [&'static str]) {
- for item in items {
- unsafe{vStrSlc.push(item);}
- }
- }
- fn f2()->&'static [&'static str]{
- let aLen = unsafe{vStrSlc.len()};
- static mut rslt:Vec<&str> = Vec::new();
- unsafe{
- rslt = vec![""; aLen];
- for i in 0..aLen {
- rslt[i] = vStrSlc.pop().unwrap();
- }
- rslt.as_slice()
- }
- }
- }
- impl Trait1 for &'static [i32] {
- fn f1(items: &'static [i32]) {
- for item in items {
- unsafe{vI32.push(*item);}
- }
- }
- fn f2()->&'static [i32]{
- let aLen = unsafe{vI32.len()};
- static mut rslt:Vec<i32> = Vec::new();
- unsafe{
- rslt = vec![0; aLen];
- for i in 0..aLen {
- rslt[i] = vI32.pop().unwrap();
- }
- rslt.as_slice()
- }
- }
- }
- fn main() {
- let arg:&'static [&'static str] = &["abc", "def", "ghi"];
- Trait1::f1(arg);
- println!("{:?}", <&'static [&'static str] as Trait1>::f2()); //["ghi", "def", "abc"]
- let arg:&'static [i32] = &[123, 456, 789];
- Trait1::f1(arg);
- println!("{:?}", <&'static [i32] as Trait1>::f2()); //[789, 456, 123]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement