Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

what does the '->' token mean in Rust?

I’m digging into Rust for the first time, with a primarily ObjC and Javascript (sigh) background, and working with a few of the playgrounds.

I’m trying to understand the -> (aka "thin arrow??") symbol in Rust and how I am supposed to interpret this when reading Rust statements

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In rust -> meaning the return of the function. In rust function exactly need to specify the return type so when you declare a function that return that adds one to the integer you have to specify the return type i32 of the function

    fn add_one(x:i32) -> i32 
    {
       x+1
    }

you have to declare x+1 to add one and return the value. note that when you return the value you do not declare semicolon after x+1; like that. declaring semicolon means its an expression and not return. in rust returning values they do not end with semicolon.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading