Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7631871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:28:08+00:00 2026-05-31T06:28:08+00:00

i write a simple rust program. fn main(){ let port = 80; result::chain(connect(localhost, port

  • 0

i write a simple rust program.

fn main(){
    let port = 80;
    result::chain(connect("localhost", port as u16)) {|s|
    send(s,str::bytes("hello world"));
};

there is some error on it.

macmatoMacBook-Air-2:rust-http kula$ rustc http.rs
http.rs:40:4: 40:52 error: cannot determine a type for this expression
http.rs:40     result::chain(connect("localhost", port as u16)) {|s|
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous errors

what happened on it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:28:09+00:00Added an answer on May 31, 2026 at 6:28 am

    The compiler has failed to infer type that this invocation of result::chain is supposed to return. It’s hard to tell for sure without knowing the types of connect and send, but I would guess that it’s because the body of your lambda block is (probably mistakenly) resulting in the nil type.

    The type of every block in rust is determined by it’s ‘tail expression’, and tail expressions are created by leaving the semicolon off of the final statement. Presumably, send returns the result type and that’s why you are using result::chain on it – so that the result of the entire expression is the result of send. To make this work the send expression should not be terminated by a semicolon. Then your lambda block will return the result of send.

    Something like this may work better:

    fn main(){
        let port = 80;
        result::chain(connect("localhost", port as u16)) {|s|
            send(s,str::bytes("hello world")) // <- no semicolon
        };
    }
    

    When type inference fails it can sometimes be helpful to breakdown expressions into smaller series of statements and insert explicit types until you figure out where the types are not matching up correctly. If I hit something like this and couldn’t figure it out by eyeballing it for a while, then I would begin rewriting it like

    fn main(){
        let port = 80;
        let conn_result: result::t<connection, str> = connect("localhost", port as u16);
        let send_fn =  fn@(s: connection) -> result::t<str, str> {
            let send_result: result<str, str> = send(s,str::bytes("hello world"));
            ret send_result;
        };
        let res: result<str, str> = result::chain(conn_result, send_fn);
    }
    

    Of course substituting whatever types connect and send actually use. At some point in the process of pulling everything apart you will find out where you and the compiler disagree.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write simple program using ONLY for loop ( if then
i'm trying to write simple tcp\ip client-server. here is server code: internal class Program
I need to write simple application that can send and receive some UDP package
I am trying to write simple Visual Studio Add-In for code generation. In my
I'm trying to write simple proxy server for some purpose. In it I use
I had a task to write simple game simulating two players picking up 1-3
I had a task to write simple game simulating two players picking up 1-3
As a part of our application I need to write simple workflow system which
I've been playing with OpenCL recently, and I'm able to write simple kernels that
i write a simple webservice code in asp.net when i build the service and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.