Skip to content

Instantly share code, notes, and snippets.

@fef1312
Created December 7, 2022 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fef1312/afa79668e683669594f7c21cea32412e to your computer and use it in GitHub Desktop.
Save fef1312/afa79668e683669594f7c21cea32412e to your computer and use it in GitHub Desktop.
the thing where rustc does the thing
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