# Immutable reference to struct as param in function

**URL:** <https://forums.swift.org/t/immutable-reference-to-struct-as-param-in-function/37770>\
**Category:** Using Swift\
**Created:** [June 21, 2020, 3:39am UTC](https://forums.swift.org/t/immutable-reference-to-struct-as-param-in-function/37770 "2020-06-21T03:39:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asdf](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@asdf](https://forums.swift.org/u/asdf)\
**Post date:** [June 21, 2020, 3:39am UTC](https://forums.swift.org/t/immutable-reference-to-struct-as-param-in-function/37770/1 "2020-06-21T03:39:43Z")

</div>

Hello!  
Is it possible to make immutable reference to struct as param in function?  
For e.g., in rust:  
struct Test{  
x:i32  
}  
fn read\_test\_field(test: &Test) {  
println!("{}",test.x);  
}

---

<div class="post-metadata">

**Author:** ![John\_McCall](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/john_mccall/32/1351_2.png) [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Post date:** [June 21, 2020, 5:35am UTC](https://forums.swift.org/t/immutable-reference-to-struct-as-param-in-function/37770/2 "2020-06-21T05:35:07Z")

</div>

Not yet. We do have this concept in the implementation, and at that level functions do generally expect their parameters to be "borrowed" this way. However, the _semantics_ of arguments in Swift are that they're passed as copies, and passing them borrowed is just an optimization. There are many cases where this optimization works, but sometimes the compiler runs into the limits of what it can prove, and in these cases it must conservatively generate a copy and then borrow from that copy instead. I would eventually like to add some way for programmers to explicitly optimize their code by passing arguments as borrows, but for now there's no way to do it except it by writing code that's obvious enough to the optimizer.

Relatedly, we do hope to someday add non-copyable types to Swift, and to support them it will be necessary to let programmers distinguish between owned and borrowed parameters.
