Files
tonic/tests/extern_path/my_application/src/main.rs
T
Danny HuaandGitHub 1b3d107206 fix(build): Don't replace extern_paths (#261)
* don't replace extern_path'd paths

tonic-build will replace all paths except for google well known types
with one rooted at the super module. For paths that have already been
replaced with a fully qualified path via the extern_path config option,
(e.g. "::uuid::Uuid"), this results in an invalid path
(e.g. "super::::uuid::Uuid"), and a build failure. These paths should
also be excluded when prefixing relative modules with super.

* add doc in tonic-build clarifying extern_path

extern_path expects fully qualified proto and rust paths

* add test cast case for extern path fix

add a test that extern path does indeed result in service types using
the specified type from an external crate. we test this by creating a
service type that has a proto from a different crate, and asserting that
it does indeed impl a trait from that crate

* add license/publish to extern_path test crates
2020-02-18 09:56:32 -05:00

27 lines
799 B
Rust

use uuid::DoSomething;
mod pb {
tonic::include_proto!("my_application");
}
fn main() {
// verify that extern_path to replace proto's with impl's from other crates works.
let message = pb::MyMessage {
message_id: Some(::uuid::Uuid {
uuid_str: "".to_string(),
}),
some_payload: "".to_string(),
};
dbg!(message.message_id.unwrap().do_it());
}
#[cfg(test)]
#[test]
fn service_types_have_extern_types() {
// verify that extern_path to replace proto's with impl's from other crates works.
let message = pb::MyMessage {
message_id: Some(::uuid::Uuid {
uuid_str: "not really a uuid".to_string(),
}),
some_payload: "payload".to_string(),
};
assert_eq!(message.message_id.unwrap().do_it(), "Done");
}