amarao: (Default)
[personal profile] amarao
!markdown

А вот я и дошёл до странной проблемы, которую я не могу понять.

#[derive (Debug)]
struct Count{
from: u32,
to: u32
}

#[derive (Debug)]
struct CountIterator<'a>{
params: &'a Count,
cur: u32
}

impl Count{
pub fn new(from: u32, to: u32) -> Self {
Count{from, to}
}
}

impl<'a> Iterator for CountIterator<'a>{
type Item = u32;
fn next(&mut self) -> Option<Self::Item> {
if self.cur < self.params.to{
self.cur += 1;
Some(self.cur)
}else{
None
}
}
}

impl<'a> IntoIterator for Count{
type Item = u32;
type IntoIter = CountIterator<'a>;
fn into_iter(&'a self) -> Self::IntoIter {
CountIterator{params: self, cur: self.from}
}

}

И этот код неправильный, потому что

    222 | impl<'a> IntoIterator for Count{
        |      ^^ unconstrained lifetime parameter

И я не понимаю, почему так. И оно неприятно щекочет где-то в районе type parameters, потому что редактор подсказывает, что на месте IntoIter = надо писать
type IntoIter: Iterator<Item = Self::Item> = .....;

И я ни черта не понимаю в написанном. Либо это RLS фигню пишет, либо я что-то глубоко не понимаю. Иду пересматривать про итераторы. Что-то я упускаю...
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

amarao: (Default)
amarao

April 2026

S M T W T F S
   1234
567 891011
12131415161718
19202122232425
2627282930  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Apr. 12th, 2026 08:37 pm
Powered by Dreamwidth Studios