Skip to content

Instantly share code, notes, and snippets.

@jpastuszek
Forked from rust-play/playground.rs
Created May 16, 2019 10:34
Show Gist options
  • Save jpastuszek/49ec870810aba06a9795c65a03de2d71 to your computer and use it in GitHub Desktop.
Save jpastuszek/49ec870810aba06a9795c65a03de2d71 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use std::rc::Rc;
struct ResultSet {
column_names: Rc<Vec<String>>,
rows: Vec<Vec<i32>>,
}
impl ResultSet {
fn pop(&mut self) -> Option<Row> {
self.rows.pop().map(|columns| Row {
column_names: self.column_names.clone(),
columns: columns,
})
}
}
struct Rows {
result_set: ResultSet,
}
struct Row {
column_names: Rc<Vec<String>>,
columns: Vec<i32>,
}
impl Iterator for Rows {
type Item = Row;
fn next(&mut self) -> Option<Row> {
self.result_set.pop()
}
}
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