# server.Server.from_env

- **Module:** server.Server
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/server.rs#L623
- **Page:** https://libtmux.org/reference/rs/server-server-from_env/

```
server.Server.from_env() -> Result<Self, Error>
```

Build a server from the `TMUX` variable tmux exports into every pane.

tmux sets `TMUX` to `<socket_path>,<server_pid>,<session_id>`. Only the
socket path is used: the pid and session id are frozen when the pane
spawns, and the session id goes stale as soon as the pane's window is
moved to another session.

Being frozen is what makes the pid worth something to a caller who
wants to know the daemon has not been replaced since. A server that
restarts on the same socket answers here just as well, and reissues
ids from the start, so [`Server::generation`] and
[`Server::require_generation`] are what tell the two apart. This does
not check on its own initiative, because that would cost a round trip
on a call documented as running no tmux command.

This runs no tmux command and does not check that the server is alive;
use [`Server::is_alive`] for that.

# Errors

Returns an error when `TMUX` is unset, empty, or not shaped like that
triple, and when the socket path it names is unusable.

## Example

```rust
let outside = libtmux::Server::from_env_value(None::<OsString>);
assert!(outside.is_err(), "a process outside tmux has no TMUX value");

let inside = libtmux::Server::from_env_value(Some("/tmp/tmux-1000/default,7,$0"))?;
assert_eq!(inside.socket_path(), std::path::Path::new("/tmp/tmux-1000/default"));
```
