Skip to content

Instantly share code, notes, and snippets.

@jhecking
Last active September 4, 2018 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhecking/a8c762afea1f48d06caba845f5c3e1e7 to your computer and use it in GitHub Desktop.
Save jhecking/a8c762afea1f48d06caba845f5c3e1e7 to your computer and use it in GitHub Desktop.
#[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