Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug)]
- struct test<'a> {
- part1: &'a str,
- part2: &'a str,
- }
- impl<'a> test<'a> {
- pub fn new() -> test<'a> {
- test {
- part1: "PART1",
- part2: "PART2",
- }
- }
- pub fn from_char(data: &[char]) -> test<'a> {
- let mut def = test::new();
- let my_str = data[0..3].iter().collect::<String>();
- def.part1 = &my_str[..];
- def
- }
- }
- fn main() {
- let a = vec!['a', 'b', 'c', 'd', 'e', 'f'];
- println!("{:?}", &a[0..3].iter().collect::<String>());
- println!("{:?}", test::new());
- println!("{:?}",test::from_char(&a));
- }
Add Comment
Please, Sign In to add comment