Created
December 7, 2022 17:31
-
-
Save fef1312/afa79668e683669594f7c21cea32412e to your computer and use it in GitHub Desktop.
the thing where rustc does the thing
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
struct Valid<T>(T); | |
trait Validate: Sized { | |
fn validate(self) -> Result<Valid<Self>, Error>; | |
} | |
struct Error { | |
msg: String, | |
} | |
impl<T> TryFrom<T> for Valid<T> | |
where | |
T: Validate, | |
{ | |
type Error = Error; | |
fn try_from(t: T) -> Result<Valid<T>, Error> { | |
t.validate() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment