Last active
September 4, 2018 11:32
-
-
Save jhecking/a8c762afea1f48d06caba845f5c3e1e7 to your computer and use it in GitHub Desktop.
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
#[derive(Debug)] | |
pub struct Bin<'a> { | |
/// Bin name | |
pub name: &'a str, | |
/// Bin value | |
pub value: i64, | |
} | |
impl<'a> Bin<'a> { | |
/// Construct a new bin given a name and a value. | |
pub fn new(name: &'a str, val: i64) -> Self { | |
Bin { | |
name: name, | |
value: val, | |
} | |
} | |
} | |
pub struct WriteCommand<'a> { | |
bins: &'a [&'a Bin<'a>], | |
} | |
impl<'a> WriteCommand<'a> { | |
pub fn new(bins: &'a [&'a Bin]) -> Self { | |
WriteCommand { bins: bins } | |
} | |
pub fn execute(&mut self) -> Result<(), String> { | |
for bin in self.bins { | |
println!("{:?}", bin); | |
} | |
Ok(()) | |
} | |
} | |
pub struct Client {} | |
impl Client { | |
pub fn new() -> Self { | |
Client {} | |
} | |
pub fn put(&self, bins: &[&Bin]) -> Result<(), String> { | |
let mut command = WriteCommand::new(bins); | |
command.execute() | |
} | |
} | |
fn main() -> Result<(), String> { | |
let client = Client::new(); | |
let bin1 = Bin::new("foo", 1); | |
let bin2 = Bin::new("bar", 2); | |
let bins = [&bin1, &bin2]; | |
client.put(&bins) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment