Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit72148fe

Browse files
author
Zibi Braniecki
committed
Use Iter.filter instead of filter_drain to support stable rust
1 parentf568392 commit72148fe

File tree

3 files changed

+106
-101
lines changed

3 files changed

+106
-101
lines changed

‎.travis.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ addons:
88
cache:cargo
99
rust:
1010
-nightly
11+
-beta
12+
-stable
1113
script:
1214
-cargo clean
1315
-cargo build

‎src/display_list/from_snippet.rs‎

Lines changed: 104 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -199,139 +199,143 @@ fn format_body(slice: &snippet::Slice, has_footer: bool) -> Vec<DisplayLine> {
199199
letmut annotations = slice.annotations.clone();
200200
for idxin0..body.len(){
201201
let(line_start, line_end) = line_index_ranges[idx];
202-
annotations.drain_filter(|annotation|{
203-
let body_idx = idx + annotation_line_count;
204-
let annotation_type =match annotation.annotation_type{
205-
snippet::AnnotationType::Error =>DisplayAnnotationType::None,
206-
snippet::AnnotationType::Warning =>DisplayAnnotationType::None,
207-
_ =>DisplayAnnotationType::from(annotation.annotation_type),
208-
};
209-
match annotation.range{
210-
(start, _)if start > line_end =>false,
211-
(start, end)if start >= line_start && end <= line_end +1 =>{
212-
let range =(start - line_start, end - line_start);
213-
body.insert(
214-
body_idx +1,
215-
DisplayLine::Source{
216-
lineno:None,
217-
inline_marks:vec![],
218-
line:DisplaySourceLine::Annotation{
219-
annotation:Annotation{
220-
annotation_type,
221-
id:None,
222-
label:format_label(Some(&annotation.label),None),
202+
// It would be nice to use filter_drain here once it's stable.
203+
annotations = annotations
204+
.into_iter()
205+
.filter(|annotation|{
206+
let body_idx = idx + annotation_line_count;
207+
let annotation_type =match annotation.annotation_type{
208+
snippet::AnnotationType::Error =>DisplayAnnotationType::None,
209+
snippet::AnnotationType::Warning =>DisplayAnnotationType::None,
210+
_ =>DisplayAnnotationType::from(annotation.annotation_type),
211+
};
212+
match annotation.range{
213+
(start, _)if start > line_end =>true,
214+
(start, end)if start >= line_start && end <= line_end +1 =>{
215+
let range =(start - line_start, end - line_start);
216+
body.insert(
217+
body_idx +1,
218+
DisplayLine::Source{
219+
lineno:None,
220+
inline_marks:vec![],
221+
line:DisplaySourceLine::Annotation{
222+
annotation:Annotation{
223+
annotation_type,
224+
id:None,
225+
label:format_label(Some(&annotation.label),None),
226+
},
227+
range,
228+
annotation_type:DisplayAnnotationType::from(
229+
annotation.annotation_type,
230+
),
231+
annotation_part:DisplayAnnotationPart::Standalone,
223232
},
224-
range,
233+
},
234+
);
235+
annotation_line_count +=1;
236+
false
237+
}
238+
(start, end)if start >= line_start && start <= line_end && end > line_end =>{
239+
if start - line_start ==0{
240+
ifletDisplayLine::Source{
241+
refmut inline_marks,
242+
..
243+
} = body[body_idx]
244+
{
245+
inline_marks.push(DisplayMark{
246+
mark_type:DisplayMarkType::AnnotationStart,
247+
annotation_type:DisplayAnnotationType::from(
248+
annotation.annotation_type,
249+
),
250+
});
251+
}
252+
}else{
253+
let range =(start - line_start, start - line_start +1);
254+
body.insert(
255+
body_idx +1,
256+
DisplayLine::Source{
257+
lineno:None,
258+
inline_marks:vec![],
259+
line:DisplaySourceLine::Annotation{
260+
annotation:Annotation{
261+
annotation_type:DisplayAnnotationType::None,
262+
id:None,
263+
label:vec![],
264+
},
265+
range,
266+
annotation_type:DisplayAnnotationType::from(
267+
annotation.annotation_type,
268+
),
269+
annotation_part:DisplayAnnotationPart::MultilineStart,
270+
},
271+
},
272+
);
273+
annotation_line_count +=1;
274+
}
275+
true
276+
}
277+
(start, end)if start < line_start && end > line_end =>{
278+
ifletDisplayLine::Source{
279+
refmut inline_marks,
280+
..
281+
} = body[body_idx]
282+
{
283+
inline_marks.push(DisplayMark{
284+
mark_type:DisplayMarkType::AnnotationThrough,
225285
annotation_type:DisplayAnnotationType::from(
226286
annotation.annotation_type,
227287
),
228-
annotation_part:DisplayAnnotationPart::Standalone,
229-
},
230-
},
231-
);
232-
annotation_line_count +=1;
233-
true
234-
}
235-
(start, end)if start >= line_start && start <= line_end && end > line_end =>{
236-
if start - line_start ==0{
288+
});
289+
}
290+
true
291+
}
292+
(start, end)if start < line_start && end >= line_start && end <= line_end =>{
237293
ifletDisplayLine::Source{
238294
refmut inline_marks,
239295
..
240296
} = body[body_idx]
241297
{
242298
inline_marks.push(DisplayMark{
243-
mark_type:DisplayMarkType::AnnotationStart,
299+
mark_type:DisplayMarkType::AnnotationThrough,
244300
annotation_type:DisplayAnnotationType::from(
245301
annotation.annotation_type,
246302
),
247303
});
248304
}
249-
}else{
250-
let range =(start - line_start, start - line_start +1);
305+
let range =(end - line_start, end - line_start +1);
251306
body.insert(
252307
body_idx +1,
253308
DisplayLine::Source{
254309
lineno:None,
255-
inline_marks:vec![],
310+
inline_marks:vec![
311+
DisplayMark{
312+
mark_type:DisplayMarkType::AnnotationThrough,
313+
annotation_type:DisplayAnnotationType::from(
314+
annotation.annotation_type,
315+
),
316+
},
317+
],
256318
line:DisplaySourceLine::Annotation{
257319
annotation:Annotation{
258-
annotation_type:DisplayAnnotationType::None,
320+
annotation_type,
259321
id:None,
260-
label:vec![],
322+
label:format_label(Some(&annotation.label),None),
261323
},
262324
range,
263325
annotation_type:DisplayAnnotationType::from(
264326
annotation.annotation_type,
265327
),
266-
annotation_part:DisplayAnnotationPart::MultilineStart,
328+
annotation_part:DisplayAnnotationPart::MultilineEnd,
267329
},
268330
},
269331
);
270332
annotation_line_count +=1;
333+
false
271334
}
272-
false
273-
}
274-
(start, end)if start < line_start && end > line_end =>{
275-
ifletDisplayLine::Source{
276-
refmut inline_marks,
277-
..
278-
} = body[body_idx]
279-
{
280-
inline_marks.push(DisplayMark{
281-
mark_type:DisplayMarkType::AnnotationThrough,
282-
annotation_type:DisplayAnnotationType::from(
283-
annotation.annotation_type,
284-
),
285-
});
286-
}
287-
false
335+
_ =>true,
288336
}
289-
(start, end)if start < line_start && end >= line_start && end <= line_end =>{
290-
ifletDisplayLine::Source{
291-
refmut inline_marks,
292-
..
293-
} = body[body_idx]
294-
{
295-
inline_marks.push(DisplayMark{
296-
mark_type:DisplayMarkType::AnnotationThrough,
297-
annotation_type:DisplayAnnotationType::from(
298-
annotation.annotation_type,
299-
),
300-
});
301-
}
302-
let range =(end - line_start, end - line_start +1);
303-
body.insert(
304-
body_idx +1,
305-
DisplayLine::Source{
306-
lineno:None,
307-
inline_marks:vec![
308-
DisplayMark{
309-
mark_type:DisplayMarkType::AnnotationThrough,
310-
annotation_type:DisplayAnnotationType::from(
311-
annotation.annotation_type,
312-
),
313-
},
314-
],
315-
line:DisplaySourceLine::Annotation{
316-
annotation:Annotation{
317-
annotation_type,
318-
id:None,
319-
label:format_label(Some(&annotation.label),None),
320-
},
321-
range,
322-
annotation_type:DisplayAnnotationType::from(
323-
annotation.annotation_type,
324-
),
325-
annotation_part:DisplayAnnotationPart::MultilineEnd,
326-
},
327-
},
328-
);
329-
annotation_line_count +=1;
330-
true
331-
}
332-
_ =>false,
333-
}
334-
});
337+
})
338+
.collect();
335339
}
336340

337341
if slice.fold{

‎src/lib.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(drain_filter)]
21
//! A library for formatting of text or programming code snippets.
32
//!
43
//! It's primary purpose is to build an ASCII-graphical representation of the snippet

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp