Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Commit ab09cb8

Browse files
authored
add more ices (#1000)
1 parent 0c73b2b commit ab09cb8

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

ices/90110.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::fs::File;
2+
use std::io::{BufReader, BufRead};
3+
use std::str::Split;
4+
use std::path::Path;
5+
6+
pub trait Parser<D>
7+
where dyn Parser<D>: Sized
8+
{
9+
fn new(split_header: Split<&str>) -> Self where Self: Sized;
10+
fn parse_line(&self, split_line: &Split<&str>) -> D;
11+
}
12+
13+
14+
pub struct CsvReader<D> {
15+
parser: Box<dyn Parser<D>>,
16+
17+
reader: BufReader<File>,
18+
buf: String, // Buffer we will read into. Avoids re-allocation on each line.
19+
path: String, // Record this so we can return more informative error messages.
20+
line: usize, // Same motivation for this.
21+
}
22+
23+
impl<D> CsvReader<D>
24+
where dyn Parser<D>: Sized
25+
{
26+
fn new<F>(path: &str, make_parser: F) -> CsvReader<D>
27+
where F: Fn(Split<char>) -> dyn Parser<D> {
28+
let file = match File::open(Path::new(path)) {
29+
Err(err) => panic!("Couldn't read {}: {}", path, err),
30+
Ok(file) => file,
31+
};
32+
33+
let mut reader = BufReader::new(file);
34+
35+
let mut buf = String::new();
36+
37+
let parser = Box::new(match reader.read_line(&mut buf) {
38+
Err(err) => panic!("Failed to read the header line from {}: {}", path, err),
39+
Ok(_) => {
40+
let split_header = buf.split(',');
41+
make_parser(split_header)
42+
},
43+
});
44+
45+
CsvReader {
46+
parser: parser,
47+
reader,
48+
buf,
49+
path: path.to_string(),
50+
line: 2,
51+
}
52+
}
53+
}
54+
55+
pub fn main() {}

ices/90150.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(inline_const)]
2+
#![feature(generic_const_exprs)]
3+
4+
const fn foo(val: usize) -> usize { val }
5+
6+
fn bar<const N: usize>(num: usize) -> &'static str
7+
where [(); foo(N)]:
8+
{
9+
match num {
10+
const { foo(N) } => "fizz",
11+
_ => "buzz"
12+
}
13+
}
14+
15+
pub fn main() {}

ices/90177.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
trait Base<'f> {
2+
type Assoc;
3+
4+
fn do_something(&self);
5+
}
6+
7+
trait ForAnyLifetime: for<'f> Base<'f> {}
8+
9+
impl<T> ForAnyLifetime for T where T: for<'f> Base<'f> {}
10+
11+
trait CanBeDynamic: ForAnyLifetime + for<'f> Base<'f, Assoc = ()> {}
12+
13+
fn foo(a: &dyn CanBeDynamic) {
14+
a.do_something();
15+
}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)