About 1,150,000 results
Open links in new tab
  1. References and Borrowing - The Rust Programming Language

    In Rust, by contrast, the compiler guarantees that references will never be dangling references: If you have a reference to some data, the compiler will ensure that the data will not go out of …

  2. rust - How to decide when function input params should be …

    Nov 13, 2020 · If the function only needs a reference, you should pass by reference. Passing by value fn foo(val: Bar) when it isn't necessary for the function to work could require the user to …

  3. Borrowing and References: Rust’s Version of ref (But Nicer)

    Apr 20, 2025 · In Rust, there's a similar concept called borrowing. It uses & and &mut, and it feels a lot like passing ref or in in C#, but with one significant difference: The compiler enforces …

  4. Rust: Pass-By-Value or Pass-By-Reference? - Ryan Levick

    Sep 12, 2018 · Pass-by-reference, on the other hand, means that when passing an argument to a function, it doesn’t copy the value but rather the argument is merely a transparent reference to …

  5. Pass by reference vs pass by value : r/rust - Reddit

    Mar 31, 2024 · If you only rarely need an owned version of the value, take it by reference and clone when you need to. That's easier on the caller and avoids redundant clones when they …

  6. How to use references in Rust - Educative

    An ampersand (&) is used with a variable’s name while passing its reference instead of its value to a function. The function’s signature should also have an ampersand with the type of …

  7. Rust References and Borrowing (With Examples) - Programiz

    References are helpful when passing values to a function that we do not want to change the ownership of. Creating a reference is known as borrowing in Rust. Let's look at an example to …

  8. Pass by Reference | Learn Rust - GitHub Pages

    The following example makes a function square() that takes a number n which is being passed by reference as a parameter to the function and prints the square of the function within the function.

  9. Safely Passing and Returning References in Rust Functions

    Jan 3, 2025 · This concept brings up the need for passing and returning references in functions safely. Managing ownership and lifetimes ensures that Rust's compile-time checks can …

  10. Function parameter types - Rust for C-Programmers

    To allow a function to read data without taking ownership, pass a shared reference (&T). This is known as borrowing.