Skip to content

Instantly share code, notes, and snippets.

@richo
Created February 26, 2020 22:20
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 richo/4570549a0e016384ced4700c6e223e83 to your computer and use it in GitHub Desktop.
Save richo/4570549a0e016384ced4700c6e223e83 to your computer and use it in GitHub Desktop.
use std::io::{self, Read};
use protobuf;
use rocket::{Request, Data, Outcome::*};
use rocket::data::{FromDataSimple, Outcome, Transform, Transformed};
use rocket::http::Status;
// We have to involve a local trait for *reasons*
trait FromDataMarker {}
impl<T> FromDataMarker for T where T: protobuf::Message {}
impl<T> FromDataSimple for T
where T: protobuf::Message + FromDataMarker {
type Error = ();
fn from_data(req: &Request, data: Data) -> Outcome<T, String> {
let mut object = T::new();
// object.merge_from(data);
Success(object)
}
}
@richo
Copy link
Author

richo commented Feb 26, 2020

^ type parameter T must be used as the type parameter for some local type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment