Skip to main content

Module reloading_docs

Module reloading_docs 

Source
Expand description

§Reloading

Rust module provides reloading feature that can be used for easier development, avoiding server restart and client reconnect

note: currently, it works a bit better on Linux than on Windows. Background threads spawned by Rust resources are not checked on Windows which can lead to Undefined Behavior. See also before_unload.

§How to use

note: ready-made example.

To use it:

…compile rust-module with reloading enabled:

cargo altvup release --reloading

…compile your resource with reloading feature enabled on altv crate, you can do so by adding the following to your Cargo.toml:

[features]
reloading = ["altv/reloading"]

…and running something like:

cargo build --features reloading

…now start altv-server, run in it:

stop <your resource name>

…recompile your resource and run in altv-server:

start <your resource name>

note: stop and start are alt:V built-in commands. It’s also possible to reload resources programmatically using altv::Resource::current().stop/start

§Cleanup at unloading

Rust module will cleanup everything owned (created) by Rust resource when it’s unloaded:

  • Destroy all baseobjects (colshapes, vehicles, etc.)
  • Delete all metadata, including metadata set on connected players

note: connected players do not disappear in a magical way when resource is unloaded, so be prepared to handle already connected players when resource starts in a different way, player connect event won’t be called for them.

§before_unload

Rust module provides altv::before_unload callback API when something needs to be cleaned up manually when resource is unloaded.

§More details

For more details about reloading feature see relib. About caveats, only File descriptors and network sockets and Dead locks apply to Rust module, txt the rest.