Crate time

source ·
Expand description

Pimalaya time management

Rust library to manange your time.

The core concept is the Timer, which gathers information about the cycle and the state. The Server runs the timer and accepts connection from Clients thanks to ServerBinders. The clients communicate with the server using Requests and Responses, which allow them to control the timer.

┌────────────────────────┐
│Server                  │
│             ┌────────┐ │ Request ┌────────┐
│             │        │◄├─────────┤        │
│    ┌────────┤Binder A│ │         │Client A│
│    │        │        ├─┼────────►│        │
│    │        └────────┘ │Response └────────┘
│    │                   │
│    ▼        ┌────────┐ │         ┌────────┐
│ ┌─────┐     │        │◄├─────────┤        │
│ │Timer│◄────┤Binder B│ │         │Client B│
│ └─────┘     │        ├─┼────────►│        │
│    ▲        └────────┘ │         └────────┘
│    │                   │
│    │        ┌────────┐ │         ┌────────┐
│    │        │        │◄├─────────┤        │
│    └────────┤Binder C│ │         │Client C│
│             │        ├─┼────────►│        │
│             └────────┘ │         └────────┘
│                        │
└────────────────────────┘
use std::{thread, time::Duration};
use time::{ServerBuilder, ServerEvent, TcpBind, TcpClient, TimerEvent};

const HOST: &str = "127.0.0.1";
const PORT: u16 = 3000;

pub fn main() {
    let server = ServerBuilder::new()
        .with_server_handler(|event: ServerEvent| {
            println!("server event: {:?}", event);
            Ok(())
        })
        .with_timer_handler(|event: TimerEvent| {
            println!("timer event: {:?}", event);
            Ok(())
        })
        .with_binder(TcpBind::new(HOST, PORT))
        .with_pomodoro_config()
        .build()
        .unwrap();

    server
        .bind_with(|| {
            let client = TcpClient::new(HOST, PORT);
            client.start().unwrap();
            thread::sleep(Duration::from_secs(1));
            client.pause().unwrap();
            thread::sleep(Duration::from_secs(1));
            let timer = client.get().unwrap();
            println!("current timer: {:?}", timer);
            Ok(())
        })
        .unwrap();
}

Structs

Enums

Traits

Type Aliases