implement From<X> for XCommand
All checks were successful
Rust / build (pull_request) Successful in 2m15s
All checks were successful
Rust / build (pull_request) Successful in 2m15s
This commit is contained in:
parent
cbab86bd93
commit
1cf37413e6
|
@ -2,7 +2,7 @@
|
|||
|
||||
use clap::Parser;
|
||||
use servicepoint::{
|
||||
CharGrid, CharGridCommand, ClearCommand, Connection, Origin, UdpConnection,
|
||||
CharGrid, CharGridCommand, ClearCommand, Connection, UdpConnection,
|
||||
TILE_WIDTH,
|
||||
};
|
||||
|
||||
|
@ -42,9 +42,6 @@ fn main() {
|
|||
}
|
||||
|
||||
let text = cli.text.join("\n");
|
||||
let command = CharGridCommand {
|
||||
grid: CharGrid::wrap_str(TILE_WIDTH, &text),
|
||||
origin: Origin::ZERO,
|
||||
};
|
||||
let command: CharGridCommand = CharGrid::wrap_str(TILE_WIDTH, &text).into();
|
||||
connection.send(command).expect("sending text failed");
|
||||
}
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
use clap::Parser;
|
||||
use servicepoint::{
|
||||
Bitmap, BitmapCommand, Brightness, BrightnessGrid, BrightnessGridCommand,
|
||||
CompressionCode, Connection, DataRef, Grid, Origin, UdpConnection,
|
||||
TILE_HEIGHT, TILE_WIDTH,
|
||||
Connection, DataRef, Grid, UdpConnection, TILE_HEIGHT, TILE_WIDTH,
|
||||
};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
|
@ -21,12 +20,9 @@ fn main() {
|
|||
let mut bitmap = Bitmap::max_sized();
|
||||
bitmap.fill(true);
|
||||
|
||||
let command = BitmapCommand {
|
||||
bitmap,
|
||||
origin: Origin::ZERO,
|
||||
compression: CompressionCode::default(),
|
||||
};
|
||||
connection.send(command).expect("send failed");
|
||||
connection
|
||||
.send(BitmapCommand::from(bitmap))
|
||||
.expect("send failed");
|
||||
|
||||
let max_brightness: u8 = Brightness::MAX.into();
|
||||
let mut brightnesses = BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT);
|
||||
|
@ -35,9 +31,6 @@ fn main() {
|
|||
*byte = Brightness::try_from(level).unwrap();
|
||||
}
|
||||
|
||||
let command = BrightnessGridCommand {
|
||||
origin: Origin::ZERO,
|
||||
grid: brightnesses,
|
||||
};
|
||||
let command: BrightnessGridCommand = brightnesses.into();
|
||||
connection.send(command).expect("send failed");
|
||||
}
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
use clap::Parser;
|
||||
use rand::{distributions, Rng};
|
||||
use servicepoint::{
|
||||
Bitmap, BitmapCommand, CompressionCode, Connection, Grid, Origin,
|
||||
UdpConnection, FRAME_PACING,
|
||||
Bitmap, BitmapCommand, Connection, Grid, UdpConnection, FRAME_PACING,
|
||||
};
|
||||
use std::thread;
|
||||
|
||||
|
@ -24,11 +23,7 @@ fn main() {
|
|||
let mut field = make_random_field(cli.probability);
|
||||
|
||||
loop {
|
||||
let command = BitmapCommand {
|
||||
bitmap: field.clone(),
|
||||
origin: Origin::ZERO,
|
||||
compression: CompressionCode::default(),
|
||||
};
|
||||
let command = BitmapCommand::from(field.clone());
|
||||
connection.send(command).expect("could not send");
|
||||
thread::sleep(FRAME_PACING);
|
||||
field = iteration(field);
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
use clap::Parser;
|
||||
use servicepoint::{
|
||||
Bitmap, BitmapCommand, CompressionCode, Connection, Grid, Origin,
|
||||
UdpConnection, FRAME_PACING, PIXEL_HEIGHT, PIXEL_WIDTH,
|
||||
Bitmap, BitmapCommand, Connection, Grid, UdpConnection, FRAME_PACING,
|
||||
PIXEL_HEIGHT, PIXEL_WIDTH,
|
||||
};
|
||||
use std::thread;
|
||||
|
||||
|
@ -25,11 +25,7 @@ fn main() {
|
|||
bitmap.set((y + x_offset) % PIXEL_WIDTH, y, true);
|
||||
}
|
||||
|
||||
let command = BitmapCommand {
|
||||
bitmap: bitmap.clone(),
|
||||
compression: CompressionCode::default(),
|
||||
origin: Origin::ZERO,
|
||||
};
|
||||
let command = BitmapCommand::from(bitmap.clone());
|
||||
connection.send(command).expect("send failed");
|
||||
thread::sleep(FRAME_PACING);
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ use clap::Parser;
|
|||
use rand::Rng;
|
||||
use servicepoint::{
|
||||
Bitmap, BitmapCommand, Brightness, BrightnessCommand, BrightnessGrid,
|
||||
BrightnessGridCommand, CompressionCode, Connection, Grid, Origin,
|
||||
UdpConnection, TILE_HEIGHT, TILE_WIDTH,
|
||||
BrightnessGridCommand, Connection, Grid, Origin, UdpConnection,
|
||||
TILE_HEIGHT, TILE_WIDTH,
|
||||
};
|
||||
use std::time::Duration;
|
||||
|
||||
|
@ -32,11 +32,7 @@ fn main() {
|
|||
let mut filled_grid = Bitmap::max_sized();
|
||||
filled_grid.fill(true);
|
||||
|
||||
let command = BitmapCommand {
|
||||
bitmap: filled_grid,
|
||||
origin: Origin::ZERO,
|
||||
compression: CompressionCode::default(),
|
||||
};
|
||||
let command = BitmapCommand::from(filled_grid);
|
||||
connection.send(command).expect("send failed");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
//! Example for how to use the WebSocket connection
|
||||
|
||||
use servicepoint::{
|
||||
Bitmap, BitmapCommand, ClearCommand, CompressionCode, Connection, Grid,
|
||||
Origin, WebsocketConnection,
|
||||
Bitmap, BitmapCommand, ClearCommand, Connection, Grid, WebsocketConnection,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
|
@ -14,10 +13,6 @@ fn main() {
|
|||
let mut pixels = Bitmap::max_sized();
|
||||
pixels.fill(true);
|
||||
|
||||
let command = BitmapCommand {
|
||||
bitmap: pixels,
|
||||
origin: Origin::ZERO,
|
||||
compression: CompressionCode::default(),
|
||||
};
|
||||
let command = BitmapCommand::from(pixels);
|
||||
connection.send(command).unwrap();
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
use clap::Parser;
|
||||
use servicepoint::{
|
||||
Bitmap, BitmapCommand, CompressionCode, Connection, Grid, Origin,
|
||||
UdpConnection, FRAME_PACING, PIXEL_HEIGHT, PIXEL_WIDTH,
|
||||
Bitmap, BitmapCommand, Connection, Grid, UdpConnection, FRAME_PACING,
|
||||
PIXEL_HEIGHT, PIXEL_WIDTH,
|
||||
};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
@ -35,11 +35,7 @@ fn main() {
|
|||
enabled_pixels.set(x_offset % PIXEL_WIDTH, y, false);
|
||||
}
|
||||
|
||||
let command = BitmapCommand {
|
||||
bitmap: enabled_pixels.clone(),
|
||||
origin: Origin::ZERO,
|
||||
compression: CompressionCode::default(),
|
||||
};
|
||||
let command = BitmapCommand::from(enabled_pixels.clone());
|
||||
connection
|
||||
.send(command)
|
||||
.expect("could not send command to display");
|
||||
|
|
|
@ -106,6 +106,10 @@ mod tests {
|
|||
#[cfg(feature = "rand")]
|
||||
fn test() {
|
||||
let mut rng = rand::thread_rng();
|
||||
assert_ne!(rng.r#gen::<Brightness>(), rng.r#gen());
|
||||
// two so test failure is less likely
|
||||
assert_ne!(
|
||||
[rng.r#gen::<Brightness>(), rng.r#gen()],
|
||||
[rng.r#gen(), rng.r#gen()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,6 +121,16 @@ impl From<BitmapCommand> for TypedCommand {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Bitmap> for BitmapCommand {
|
||||
fn from(bitmap: Bitmap) -> Self {
|
||||
Self {
|
||||
bitmap,
|
||||
origin: Origin::default(),
|
||||
compression: CompressionCode::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BitmapCommand {
|
||||
fn packet_into_bitmap_win(
|
||||
packet: Packet,
|
||||
|
|
|
@ -127,6 +127,17 @@ impl From<BitVecCommand> for TypedCommand {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<BitVec> for BitVecCommand {
|
||||
fn from(bitvec: BitVec) -> Self {
|
||||
Self {
|
||||
bitvec,
|
||||
operation: BinaryOperation::default(),
|
||||
offset: Offset::default(),
|
||||
compression: CompressionCode::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -25,6 +25,15 @@ impl TryFrom<BrightnessGridCommand> for Packet {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<BrightnessGrid> for BrightnessGridCommand {
|
||||
fn from(grid: BrightnessGrid) -> Self {
|
||||
Self {
|
||||
grid,
|
||||
origin: Origin::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for BrightnessGridCommand {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
|
|
|
@ -82,6 +82,15 @@ impl From<CharGridCommand> for TypedCommand {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<CharGrid> for CharGridCommand {
|
||||
fn from(grid: CharGrid) -> Self {
|
||||
Self {
|
||||
grid,
|
||||
origin: Origin::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::commands::tests::{round_trip, TestImplementsCommand};
|
||||
|
|
|
@ -90,6 +90,15 @@ impl From<Cp437GridCommand> for TypedCommand {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Cp437Grid> for Cp437GridCommand {
|
||||
fn from(grid: Cp437Grid) -> Self {
|
||||
Self {
|
||||
grid,
|
||||
origin: Origin::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in a new issue