Created
May 16, 2019 10:34
-
-
Save rust-play/dcd7cbb6393065ae3cb08056904c84ce 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
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