-
-
Save jpastuszek/d07391f617ac8a3656ecb41c4462ec97 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ResultSet { | |
column_names: Vec<String>, | |
rows: Vec<Vec<i32>>, | |
} | |
impl ResultSet { | |
fn get<'rs>(&'rs self, row_no: usize) -> Option<Row<'rs>> { | |
self.rows.get(row_no).map(|columns| Row { | |
column_names: self.column_names.as_slice(), | |
columns: columns.as_slice(), | |
}) | |
} | |
} | |
struct Rows<'rs> { | |
result_set: &'rs ResultSet, | |
row_no: usize, | |
} | |
struct Row<'rs> { | |
column_names: &'rs[String], | |
columns: &'rs[i32], | |
} | |
impl<'rs> Iterator for Rows<'rs> { | |
type Item = Row<'rs>; | |
fn next(&mut self) -> Option<Row<'rs>> { | |
let r = self.result_set.get(self.row_no); | |
self.row_no += 1; | |
r | |
} | |
} | |
fn main() { | |
println!("{}", 4.0f64.powf(1.0/3.0)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment