Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created May 16, 2019 10:29
Show Gist options
  • Save rust-play/1327123b2f5755dca63d658b3766b205 to your computer and use it in GitHub Desktop.
Save rust-play/1327123b2f5755dca63d658b3766b205 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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