From e3c418efcfe00f76e3eaa036d637bde3917cceb7 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Tue, 25 Jun 2024 22:33:53 +0200 Subject: [PATCH] add examples for brightness, replace ByteGrid with PrimitiveGrid --- crates/servicepoint/src/brightness.rs | 25 +++++++++++++++++++++++ crates/servicepoint/src/primitive_grid.rs | 12 +++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/crates/servicepoint/src/brightness.rs b/crates/servicepoint/src/brightness.rs index dae3450..6065266 100644 --- a/crates/servicepoint/src/brightness.rs +++ b/crates/servicepoint/src/brightness.rs @@ -1,4 +1,5 @@ use crate::{Grid, PrimitiveGrid}; + #[cfg(feature = "rand")] use rand::{ distributions::{Distribution, Standard}, @@ -6,10 +7,34 @@ use rand::{ }; /// A display brightness value, checked for correct value range +/// +/// # Examples +/// +/// ``` +/// # use servicepoint::{Brightness, Command, Connection}; +/// let b = Brightness::MAX; +/// let val: u8 = b.into(); +/// +/// let b = Brightness::try_from(7).unwrap(); +/// # let connection = Connection::open("127.0.0.1:2342").unwrap(); +/// let result = connection.send(Command::Brightness(b)); +/// ``` #[derive(Debug, Copy, Clone, PartialEq)] pub struct Brightness(u8); /// A grid containing brightness values. +/// +/// # Examples +/// +/// ```rust +/// # use servicepoint::{Brightness, BrightnessGrid, Command, Connection, Grid, Origin}; +/// let mut grid = BrightnessGrid::new(2,2); +/// grid.set(0, 0, Brightness::MIN); +/// grid.set(1, 1, Brightness::MIN); +/// +/// # let connection = Connection::open("127.0.0.1:2342").unwrap(); +/// connection.send(Command::CharBrightness(Origin::new(3, 7), grid)).unwrap() +/// ``` pub type BrightnessGrid = PrimitiveGrid; impl From for u8 { diff --git a/crates/servicepoint/src/primitive_grid.rs b/crates/servicepoint/src/primitive_grid.rs index d96221b..578379e 100644 --- a/crates/servicepoint/src/primitive_grid.rs +++ b/crates/servicepoint/src/primitive_grid.rs @@ -21,7 +21,7 @@ impl PrimitiveGrid { /// - width: size in x-direction /// - height: size in y-direction /// - /// returns: `ByteGrid` initialized to default value. + /// returns: `PrimitiveGrid` initialized to default value. pub fn new(width: usize, height: usize) -> Self { Self { data: vec![Default::default(); width * height], @@ -30,9 +30,9 @@ impl PrimitiveGrid { } } - /// Loads a `ByteGrid` with the specified dimensions from the provided data. + /// Loads a `PrimitiveGrid` with the specified dimensions from the provided data. /// - /// returns: `ByteGrid` that contains a copy of the provided data + /// returns: `PrimitiveGrid` that contains a copy of the provided data /// /// # Panics /// @@ -47,7 +47,7 @@ impl PrimitiveGrid { } } - /// Iterate over all cells in `ByteGrid`. + /// Iterate over all cells in `PrimitiveGrid`. /// /// Order is equivalent to the following loop: /// ``` @@ -63,7 +63,7 @@ impl PrimitiveGrid { self.data.iter() } - /// Iterate over all rows in `ByteGrid` top to bottom. + /// Iterate over all rows in `PrimitiveGrid` top to bottom. pub fn iter_rows(&self) -> IterRows { IterRows { byte_grid: self, @@ -113,7 +113,7 @@ impl PrimitiveGrid { } impl Grid for PrimitiveGrid { - /// Sets the value of the cell at the specified position in the `ByteGrid. + /// Sets the value of the cell at the specified position in the `PrimitiveGrid. /// /// # Arguments ///