Skip to content

Instantly share code, notes, and snippets.

@mkmik
Created February 23, 2021 16:28
Show Gist options
  • Save mkmik/bde76e12ed891e290dc492a2d9eb7071 to your computer and use it in GitHub Desktop.
Save mkmik/bde76e12ed891e290dc492a2d9eb7071 to your computer and use it in GitHub Desktop.
use std::io::Result;
fn main() -> Result<()> {
prost_build::compile_protos(&["src/tutorial.proto"], &["src/"])?;
Ok(())
}
[package]
name = "prostdemo"
version = "0.1.0"
authors = ["Marko Mikulicic <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
prost = "0.7"
bytes = "1.0"
[build-dependencies]
prost-build = { version = "0.7" }
pub mod tut {
include!(concat!(env!("OUT_DIR"), "/tutorial.rs"));
}
fn main() {
let x = tut::Person {
phone_type: tut::person::PhoneType::Home.into(),
..Default::default()
};
println!("the fields itself is an i32: {:?}", x.phone_type);
let e = tut::person::PhoneType::from_i32(x.phone_type).unwrap();
println!("You can turn it into an enum with from_i32: {:?}", e);
}
pub mod tut {
include!(concat!(env!("OUT_DIR"), "/tutorial.rs"));
}
fn main() {
let x = tut::Person {
phone_type: tut::person::PhoneType::Home.into(),
..Default::default()
};
println!("the fields itself is an i32: {:?}", x.phone_type);
let e = tut::person::PhoneType::from_i32(x.phone_type).unwrap();
println!("You can turn it into an enum with from_i32: {:?}", e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment