19 stable releases (3 major)
4.4.0 | Oct 30, 2024 |
---|---|
4.3.0 | May 3, 2024 |
4.2.0 | Mar 20, 2024 |
3.3.2 | Jan 15, 2024 |
1.0.0 | Mar 10, 2023 |
#906 in Science
82 downloads per month
Used in 12 crates
(10 directly)
420KB
2.5K
SLoC
gmt_dos-clients
The crate defines the client-to-actor interface and a set of "generic" clients.
If the crate is required solely to implement the interface for a new client, add it to the list of dependencies like so:
cargo add --no-default-features --features interface gmt_dos-clients
lib.rs
:
Actors clients
The module holds the implementation of the different clients that can be assigned to Actors.
Any structure can become a client to an Actor if it implements the Update trait with either or both Read and Write traits.
Example
Logging
A simple logger with a single entry:
use gmt_dos_clients::Logging;
let logging = Logging::<f64>::default();
A logger with 2 entries and pre-allocated with 1000 elements:
use gmt_dos_clients::Logging;
let logging = Logging::<f64>::default().n_entry(2).capacity(1_000);
Signals
A constant signal for 100 steps
use gmt_dos_clients::{Signals, Signal};
let signal: Signals = Signals::new(1, 100).signals(Signal::Constant(3.14));
A 2 outputs signal made of a constant and a sinusoid for 100 steps
use gmt_dos_clients::{Signals, Signal};
let signal: Signals = Signals::new(2, 100)
.output_signal(0, Signal::Constant(3.14))
.output_signal(1, Signal::Sinusoid{
amplitude: 1f64,
sampling_frequency_hz: 1000f64,
frequency_hz: 20f64,
phase_s: 0f64
});
Rate transitionner
A rate transition actor for a named output/input pair sampling a [Vec]
use gmt_dos_clients::Sampler;
#[derive(interface::UID)]
enum MyIO {};
let sampler = Sampler::<Vec<f64>, MyIO>::default();
Alias to input/output UID
Creating an alias to an already existing UniqueIdentifier (UID)
use std::sync::Arc;
use interface::{Data, Write, UniqueIdentifier,Size, UID, Update};
// Original UID
#[derive(UID)]
#[uid(data = u8)]
pub enum A {}
pub struct Client {}
impl Update for Client {}
impl Write<A> for Client {
fn write(&mut self) -> Option<Data<A>> {
Some(Data::new(10u8))
}
}
impl Size<A> for Client {
fn len(&self) -> usize {
123
}
}
// A alias with `Write` and `Size` trait implementation for `Client`
#[derive(UID)]
#[uid(data = u8)]
#[alias(name = A, client = Client, traits = Write ,Size)]
pub enum B {}
let _: <A as UniqueIdentifier>::DataType = 1u8;
let _: <B as UniqueIdentifier>::DataType = 2u8;
let mut client = Client {};
println!(
"Client Write<B>: {:?}",
<Client as Write<B>>::write(&mut client)
);
println!(
"Client Size<B>: {:?}",
<Client as Size<B>>::len(&mut client)
);
Dependencies
~3–14MB
~156K SLoC