# Function envelope::negotiate

> Chooses the highest version in both ranges (`session.hello`, the protocol).

`zaun_community_protocol::envelope::negotiate` · Function

```rust
pub fn negotiate(client: VersionRange, host: VersionRange) -> Result<u16, ErrorBody>
```

Chooses the highest version in both ranges (`session.hello`, the protocol).

# Errors
`UNSUPPORTED_VERSION` carrying `host` when the ranges do not overlap (or `client` is empty,
`min > max`). Send it as a version-1 envelope (`ResponseEnvelope::error` does); the
connection stays unnegotiated.

[Full rustdoc page](/docs/api/rust/zaun-community-protocol/zaun_community_protocol/envelope/version/fn.negotiate.html)
