My previous question tells me that rust cannot refer to itself in a structure.
using self in the new constructor
So my question will be: how to create a structure when I need to refer to myself?
We could take this structure as an example:
struct SplitByChars<'a> { seperator: &'a Seperator, string: String, chars_iter: std::str::Chars<'a>, } impl<'a> SplitByChars<'a> { fn new<S>(seperator: &'a Seperator, string: S) -> SplitByChars where S: Into<String> { SplitByChars { seperator: seperator, string: string.into(), chars_iter: self.string.chars(), // error here: I cannot use self (of course, static method) } } }
I used chars_iter to provide an chars_iter line split interface.
(This is just an example, so I would like to learn about the more general idea of โโdesigning a structure, and not specifically in this case of splitting. Moreover, std is not broken.)
thanks in advance!
source share