Stream: wit-bindgen

Topic: understanding question about types in interfaces


view this post on Zulip Christoph Brewing (Apr 13 2023 at 12:13):

There is the following observation related to imported interfaces and types which I do not understand:

Given the following interface/world:

interface nicestuffhere {
    my-function: func(v0: list<u8>) -> float64
}

default world whatever {
  import sth: self.nicestuffhere
}

When the implementation wants to call function my-function
Then its parameter v0 has to be of type &[u8] where my expectation was to call a Vec<u8>. I thought so based on the assumption that among module/component boundaries data is exchanged in a shared nothing style which implies an exchange by value (in my head).

My understanding is obviously wrong but in which way?

view this post on Zulip Lann Martin (Apr 13 2023 at 12:46):

The string is copied into the callee's linear memory.

view this post on Zulip Lann Martin (Apr 13 2023 at 13:02):

Another way of thinking about it is that passing a Vec isn't passing the string data by value, its passing a (smart) pointer to the string data.

view this post on Zulip Christoph Brewing (Apr 13 2023 at 13:50):

makes sense, thank you


Last updated: Nov 22 2024 at 16:03 UTC