-
-
Save rust-play/504213373e511d375ab47419f0f1815d 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::io::Read; | |
use std::io::Cursor; | |
struct B(String); | |
struct RefPairA<'b>(&'b B, String); | |
trait GetPair { | |
fn pair(&self) -> (&str, &str); | |
} | |
impl<'b> GetPair for RefPairA<'b> { | |
fn pair(&self) -> (&'b str, &str) { | |
(&self.0.0, &self.1) | |
} | |
} | |
fn get_data_a(p: &RefPairA) -> impl Read { | |
let (b, s) = p.pair(); | |
Cursor::new(format!("{}/{}", b, s).into_bytes()) | |
} | |
fn get_data(p: &impl GetPair) -> impl Read { | |
let (b, s) = p.pair(); | |
Cursor::new(format!("{}/{}", b, s).into_bytes()) | |
} | |
fn data_a() -> impl Read { | |
let b = B("foo".to_owned()); | |
let a = RefPairA(&b, "bar".to_owned()); | |
get_data_a(&a) | |
} | |
fn data() -> impl Read { | |
let b = B("foo".to_owned()); | |
let a = RefPairA(&b, "bar".to_owned()); | |
get_data(&a) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment