Created
September 20, 2019 20:55
-
-
Save rust-play/ff0592552f65e8fa205d4a4af0ba3bc0 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
fn main() { | |
foo("abc"); | |
} | |
struct Value(); | |
struct StrDeserializer<'a>(&'a str); | |
impl<'a> StrDeserializer<'a> { | |
fn new(s: &'a str) -> Self { | |
StrDeserializer(s) | |
} | |
} | |
trait Deserializer { } | |
impl Deserializer for Value { } | |
impl Deserializer for &Value { } | |
impl<'a> Deserializer for &mut StrDeserializer<'a> { } | |
// I want this function to remain unchanged | |
fn gets_called<D: Deserializer>(_d: D) { } | |
// I want to change function this into something that can take both &str and Value (or &Value) | |
fn foo(s: &str) { | |
let mut de = StrDeserializer::new(s); | |
gets_called(&mut de); | |
} | |
fn foo2(v: &Value) { | |
gets_called(v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment