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 Client
s thanks to ServerBind
ers. The
clients communicate with the server using Request
s and
Response
s, 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
- Convenient builder that helps you to build a
Server
. - Thread safe version of the
ServerState
which allows theServer
to mutate its state even from astd::thread::spawn
). - Thread safe version of the
Timer
. - The timer.
- The timer configuration.
- The timer cycle.
- The timer cycles list.
Enums
- The timer event.
- The timer loop.
- The timer state.
Traits
- Clients must implement this trait. Only the
Client::send
function needs to be implemented: it should describe how to connect and send requests to the server. - Clients may implement this trait, but it is not mandatory. It can be seen as a helper: by implementing the
ClientStream::read
and theClientStream::write
functions, the trait can deduce how to handle a request. ServerBind
ers must implement this trait.ServerBind
ers may implement this trait, but it is not mandatory. It can be seen as a helper: by implementing theServerStream::read
and theServerStream::write
functions, the trait can deduce how to handle a request.
Type Aliases
- The timer changed handler.