Live data from Hacker News

Should small Rust structs be passed by-copy or by-borrow?

forrestthewoods.com

111–115 of 115 posts

Re: Should small Rust structs be passed by-copy or by-borrow?

#112
post #103

Earlier quoted context omitted.

> a) the language designers decided to cram several paradigms into it, including a heavier than usual dose of functional. Rust is actually really close to JavaScript in that regard, with its mix of OOP-without-inheritance and the whole collection of functional method on Arrays and iterators ( map , reduce , etc.). And while People have a ton of complain about JavaScript, none of them is «the JavaScript language is to…

> What ? Do you mean “ not coming from the C language family”? Because its syntax is clearly in the C-family (semicolon, braces). My guess is that they're talking about the syntax inspired from its ML roots, like `let/let mut`, `->` for return types, and `:` for type annotations. I personally prefer these to the C-style equivalents, but I've talked with enough people who haven't used an ML-like language that I'm not…

Thanks I haven't thought about that part, but nowadays it has become kind of mainstream: JavaScript uses let/const and typescript uses the colon notation for type. And I've never heard anyone complaining about those for the complexity of their syntax.

Re: Should small Rust structs be passed by-copy or by-borrow?

#113
post #71

Earlier quoted context omitted.

That's interesting, and a bit surprising. I know Ada does this, but it's explicit about only specifying semantics ("in, "out" or "in out") and letting the compiler decide. Surely C or C++ optimizers won't do this?

Let's disregard inlining etc, so that we have actual function calls in both languages. C and Rust compilers do the same thing - they follow a calling convention. It will tell you how to pass a struct, if it should be passed as a pointer or in registers etc.

Rust doesn't have a defined, standardized, binary calling convention, to the extent that C does.

Re: Should small Rust structs be passed by-copy or by-borrow?

#114
post #71

Earlier quoted context omitted.

Let's disregard inlining etc, so that we have actual function calls in both languages. C and Rust compilers do the same thing - they follow a calling convention. It will tell you how to pass a struct, if it should be passed as a pointer or in registers etc.

Rust doesn't have a defined, standardized, binary calling convention, to the extent that C does.

I agree, but that doesn't mean that it picks different calling conventions for each function call it compiles or something like that. Each version & platform of Rustc will have a calling convention that it sticks to when compiling function calls.

Re: Should small Rust structs be passed by-copy or by-borrow?

#115

Earlier quoted context omitted.

Rust doesn't have a defined, standardized, binary calling convention, to the extent that C does.

I agree, but that doesn't mean that it picks different calling conventions for each function call it compiles or something like that. Each version & platform of Rustc will have a calling convention that it sticks to when compiling function calls.

It can pick a calling style on a per function basis.
Post reply on HN