-
-
Save rust-play/d96640f6e2477fa35aa08d234c476faf to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or 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::error::Error; | |
use std::slice::Iter; | |
struct Query { | |
query: String, | |
} | |
struct Response { | |
response: u64, | |
} | |
trait Responsability { | |
fn take(&self, iterator: Iter<Box<dyn Responsability>>, query: Query) -> Result<Response, Box<dyn Error>>; | |
} | |
struct ResponsabilityChain { | |
responsabilities: Vec<Box<dyn Responsability>>, | |
} | |
impl ResponsabilityChain { | |
pub fn new(responsabilities: Vec<Box<dyn Responsability>>) -> Self { | |
Self { responsabilities } | |
} | |
pub fn launch(&self, query: Query) -> Result<Response, Box<dyn Error>> { | |
let mut iterator: Iter<Box<dyn Responsability>> = self.responsabilities.iter(); | |
let responsability = iterator.next().unwrap(); | |
responsability.take(iterator, query) | |
} | |
} | |
fn main() { | |
println!("Helo, world!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment