Skip to main content

ObserverHandle

Struct ObserverHandle 

Source
pub struct ObserverHandle { /* private fields */ }
Expand description

Owns the Windows handles from OpenFileMappingW and MapViewOfFile.

Releases them via Drop and dereferences to ObserverData for read and write access to the memory map.

Implementations§

Source§

impl ObserverHandle

Source

pub fn new() -> Result<Self>

Opens the observer memory map and sets the refresh rate to the default of 500 ms.

Returns an error if Warcraft III is not running, or the stats observer API is otherwise unavailable.

Examples found in repository?
examples/stats.rs (line 6)
5fn main() {
6    let od = match ObserverHandle::new() {
7        Ok(od) => od,
8        Err(e) => {
9            eprintln!("Error opening observer API. Is Warcraft3 running? Error: {e:?}");
10            return;
11        }
12    };
13
14    println!("version: {}", { od.version });
15    println!("refresh rate: {}", { od.refresh_rate });
16
17    let game = &od.game;
18
19    println!("in game: {:?}", game.in_game);
20    println!(
21        "time: {:02}:{:02}",
22        game.time().as_secs() / 60,
23        game.time().as_secs() % 60
24    );
25    println!("active player count: {:?}", game.active_player_count);
26    println!("game name: {}", game.game_name);
27    println!("map name: {}", game.map_name);
28
29    loop {
30        for player in od.players.iter().take(od.game.active_player_count as usize) {
31            println!("{} has {} gold {} lumber", player.name, { player.gold }, {
32                player.lumber
33            });
34        }
35        println!();
36        std::thread::sleep(Duration::from_millis(od.refresh_rate as u64));
37    }
38}
Source

pub fn new_with_refresh_rate(duration: Duration) -> Result<Self>

Opens the observer memory map and writes duration as the refresh rate. A duration of zero disables updates.

Returns an error if Warcraft III is not running, or the stats observer API is otherwise unavailable.

Methods from Deref<Target = ObserverData>§

Source

pub fn disable(&mut self)

Disables observer updates by writing a refresh rate of 0.

Source

pub fn set_refresh_rate(&mut self, duration: Duration)

Sets the observer’s refresh rate. Sub-millisecond precision is truncated. A duration of zero disables updates.

Trait Implementations§

Source§

impl Deref for ObserverHandle

Source§

type Target = ObserverData

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for ObserverHandle

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Drop for ObserverHandle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for ObserverHandle

Source§

impl Sync for ObserverHandle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.