Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rust 1.81.0 to develop #277

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions compiler/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl<'a> MethodGen<'a> {
&format!("struct {}Method {{", self.struct_name()),
"}",
|w| {
w.write_line(&format!(
w.write_line(format!(
"service: Arc<dyn {} + Send + Sync>,",
self.service_name
));
Expand All @@ -167,7 +167,7 @@ impl<'a> MethodGen<'a> {
|w| {
w.block("fn handler(&self, ctx: ::ttrpc::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<()> {", "}",
|w| {
w.write_line(&format!("::ttrpc::request_handler!(self, ctx, req, {}, {}, {});",
w.write_line(format!("::ttrpc::request_handler!(self, ctx, req, {}, {}, {});",
proto_path_to_rust_mod(self.root_scope.find_message(self.proto.get_input_type()).get_scope().get_file_descriptor().get_name()),
self.root_scope.find_message(self.proto.get_input_type()).rust_name(),
self.name()));
Expand All @@ -184,7 +184,7 @@ impl<'a> MethodGen<'a> {
|w| {
w.block("async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<::ttrpc::Response> {", "}",
|w| {
w.write_line(&format!("::ttrpc::async_request_handler!(self, ctx, req, {}, {}, {});",
w.write_line(format!("::ttrpc::async_request_handler!(self, ctx, req, {}, {}, {});",
proto_path_to_rust_mod(self.root_scope.find_message(self.proto.get_input_type()).get_scope().get_file_descriptor().get_name()),
self.root_scope.find_message(self.proto.get_input_type()).rust_name(),
self.name()));
Expand All @@ -197,7 +197,7 @@ impl<'a> MethodGen<'a> {
|w| {
w.block("async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, inner: ::ttrpc::r#async::StreamInner) -> ::ttrpc::Result<Option<::ttrpc::Response>> {", "}",
|w| {
w.write_line(&format!("::ttrpc::async_client_streamimg_handler!(self, ctx, inner, {});",
w.write_line(format!("::ttrpc::async_client_streamimg_handler!(self, ctx, inner, {});",
self.name()));
});
});
Expand All @@ -208,7 +208,7 @@ impl<'a> MethodGen<'a> {
|w| {
w.block("async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, mut inner: ::ttrpc::r#async::StreamInner) -> ::ttrpc::Result<Option<::ttrpc::Response>> {", "}",
|w| {
w.write_line(&format!("::ttrpc::async_server_streamimg_handler!(self, ctx, inner, {}, {}, {});",
w.write_line(format!("::ttrpc::async_server_streamimg_handler!(self, ctx, inner, {}, {}, {});",
proto_path_to_rust_mod(self.root_scope.find_message(self.proto.get_input_type()).get_scope().get_file_descriptor().get_name()),
self.root_scope.find_message(self.proto.get_input_type()).rust_name(),
self.name()));
Expand All @@ -221,7 +221,7 @@ impl<'a> MethodGen<'a> {
|w| {
w.block("async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, inner: ::ttrpc::r#async::StreamInner) -> ::ttrpc::Result<Option<::ttrpc::Response>> {", "}",
|w| {
w.write_line(&format!("::ttrpc::async_duplex_streamimg_handler!(self, ctx, inner, {});",
w.write_line(format!("::ttrpc::async_duplex_streamimg_handler!(self, ctx, inner, {});",
self.name()));
});
});
Expand Down Expand Up @@ -277,8 +277,8 @@ impl<'a> MethodGen<'a> {
let method_name = self.name();
if let MethodType::Unary = self.method_type().0 {
w.pub_fn(&self.unary(&method_name), |w| {
w.write_line(&format!("let mut cres = {}::new();", self.output()));
w.write_line(&format!(
w.write_line(format!("let mut cres = {}::new();", self.output()));
w.write_line(format!(
"::ttrpc::client_request!(self, ctx, req, \"{}.{}\", \"{}\", cres);",
self.package_name,
self.service_name,
Expand All @@ -295,8 +295,8 @@ impl<'a> MethodGen<'a> {
// Unary RPC
MethodType::Unary => {
pub_async_fn(w, &self.unary(&method_name), |w| {
w.write_line(&format!("let mut cres = {}::new();", self.output()));
w.write_line(&format!(
w.write_line(format!("let mut cres = {}::new();", self.output()));
w.write_line(format!(
"::ttrpc::async_client_request!(self, ctx, req, \"{}.{}\", \"{}\", cres);",
self.package_name,
self.service_name,
Expand All @@ -307,7 +307,7 @@ impl<'a> MethodGen<'a> {
// Client Streaming RPC
MethodType::ClientStreaming => {
pub_async_fn(w, &self.client_streaming(&method_name), |w| {
w.write_line(&format!(
w.write_line(format!(
"::ttrpc::async_client_stream_send!(self, ctx, \"{}.{}\", \"{}\");",
self.package_name,
self.service_name,
Expand All @@ -318,7 +318,7 @@ impl<'a> MethodGen<'a> {
// Server Streaming RPC
MethodType::ServerStreaming => {
pub_async_fn(w, &self.server_streaming(&method_name), |w| {
w.write_line(&format!(
w.write_line(format!(
"::ttrpc::async_client_stream_receive!(self, ctx, req, \"{}.{}\", \"{}\");",
self.package_name,
self.service_name,
Expand All @@ -329,7 +329,7 @@ impl<'a> MethodGen<'a> {
// Bidirectional streaming RPC
MethodType::Duplex => {
pub_async_fn(w, &self.duplex_streaming(&method_name), |w| {
w.write_line(&format!(
w.write_line(format!(
"::ttrpc::async_client_stream!(self, ctx, \"{}.{}\", \"{}\");",
self.package_name,
self.service_name,
Expand Down Expand Up @@ -496,13 +496,13 @@ impl<'a> ServiceGen<'a> {

fn write_sync_client(&self, w: &mut CodeWriter) {
w.write_line("#[derive(Clone)]");
w.pub_struct(&self.client_name(), |w| {
w.pub_struct(self.client_name(), |w| {
w.field_decl("client", "::ttrpc::Client");
});

w.write_line("");

w.impl_self_block(&self.client_name(), |w| {
w.impl_self_block(self.client_name(), |w| {
w.pub_fn("new(client: ::ttrpc::Client) -> Self", |w| {
w.expr_block(&self.client_name(), |w| {
w.write_line("client,");
Expand All @@ -518,13 +518,13 @@ impl<'a> ServiceGen<'a> {

fn write_async_client(&self, w: &mut CodeWriter) {
w.write_line("#[derive(Clone)]");
w.pub_struct(&self.client_name(), |w| {
w.pub_struct(self.client_name(), |w| {
w.field_decl("client", "::ttrpc::r#async::Client");
});

w.write_line("");

w.impl_self_block(&self.client_name(), |w| {
w.impl_self_block(self.client_name(), |w| {
w.pub_fn("new(client: ::ttrpc::r#async::Client) -> Self", |w| {
w.expr_block(&self.client_name(), |w| {
w.write_line("client,");
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel="1.77.0"
channel="1.81.0"
profile="default"
components=["rustfmt", "clippy"]
4 changes: 2 additions & 2 deletions ttrpc-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl<'a> Run<'a> {
protobuf_path: &str,
result: &mut HashMap<String, FileDescriptorPair>,
) {
if result.get(protobuf_path).is_some() {
if result.contains_key(protobuf_path) {
return;
}

Expand All @@ -257,7 +257,7 @@ impl<'a> Run<'a> {
}

fn add_file(&mut self, protobuf_path: &str, fs_path: &Path) -> io::Result<()> {
if self.parsed_files.get(protobuf_path).is_some() {
if self.parsed_files.contains_key(protobuf_path) {
return Ok(());
}

Expand Down
8 changes: 4 additions & 4 deletions ttrpc-codegen/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ trait ToChar {

impl ToI32 for u64 {
fn to_i32(&self) -> ParserResult<i32> {
if *self <= i32::max_value() as u64 {
if *self <= i32::MAX as u64 {
Ok(*self as i32)
} else {
Err(ParserError::IntegerOverflow)
Expand All @@ -116,7 +116,7 @@ impl ToI32 for u64 {

impl ToI32 for i64 {
fn to_i32(&self) -> ParserResult<i32> {
if *self <= i32::max_value() as i64 && *self >= i32::min_value() as i64 {
if *self <= i32::MAX as i64 && *self >= i32::MIN as i64 {
Ok(*self as i32)
} else {
Err(ParserError::IntegerOverflow)
Expand All @@ -126,7 +126,7 @@ impl ToI32 for i64 {

impl ToI64 for u64 {
fn to_i64(&self) -> Result<i64, ParserError> {
if *self <= i64::max_value() as u64 {
if *self <= i64::MAX as u64 {
Ok(*self as i64)
} else {
Err(ParserError::IntegerOverflow)
Expand Down Expand Up @@ -1378,7 +1378,7 @@ impl<'a> Parser<'a> {
let from = self.next_field_number()?;
let to = if self.next_ident_if_eq("to")? {
if self.next_ident_if_eq("max")? {
i32::max_value()
i32::MAX
} else {
self.next_field_number()?
}
Expand Down
Loading