Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct OutputBuilder<'a> {
- o: &'a mut Output,
- }
- struct DebugObject {}
- struct DebugOutput {}
- trait Output {
- fn out(&mut self) -> OutputBuilder;
- }
- trait Object {}
- impl Object for DebugObject {}
- impl DebugObject {
- fn new() -> Self {
- Self {}
- }
- fn me() -> Self {
- Self {}
- }
- }
- impl DebugOutput {
- fn new() -> Self {
- Self {}
- }
- }
- impl<'a> OutputBuilder<'a> {
- fn new(o: &'a mut Output) -> Self {
- Self { o }
- }
- fn a<'b, T: Object>(self, _obj: &'b T) -> Self {
- self
- }
- }
- impl Output for DebugOutput {
- fn out(&mut self) -> OutputBuilder {
- OutputBuilder::new(self as &mut Output)
- }
- }
- fn assert_call<'a, F>(func: F, _: &str)
- where
- F: for<'b> Fn(OutputBuilder<'a>, &'b DebugObject) -> OutputBuilder<'a>,
- {
- let mut out = DebugOutput::new();
- let me = DebugObject::me();
- let ob = out.out();
- func(ob, &me);
- }
- fn main() {
- let f = OutputBuilder::a::<DebugObject>;
- assert_call(f, "xxx");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement