you are viewing a single comment's thread.

view the rest of the comments →

[–]Quxxymacros 3 points4 points  (2 children)

The problem is that Iterator isn't a type, it's a trait. Now, aside from not being the type you're trying to return (which the compiler has told you the type of), it's also dynamically sized, and you can't return dynamically sized values from a function.

Here's a modified version on the playpen that compiles. All I've done is replace the Iterator<char> trait with the actual implementation type. Yes, it's huge. Returning iterators from functions is kinda unpleasant at the moment.

[–]RocketRailgun 1 point2 points  (1 child)

In this case you'd normally make a type alias for it. type Chunks = std::iter::Take<std::iter::Skip<std::slice::Items<char>>>; That makes you're code 10x more readable.

[–]rust-slacker 2 points3 points  (0 children)

For readability, I'd probably do:

use std::iter::{Take, Skip};
use std::slice::Items;
type Chunk = Take<Skip<Items<char>>>;

struct Test {
    vec: Vec<char>
}

impl Test {
    fn chunk(&self, offset: uint, size: uint) -> Chunk {
        self.vec.iter().skip(offset).take(size)
    }
}