Skip to content

Commit

Permalink
all: Use serde(default) to make the serialized strings less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
pentamassiv committed Apr 27, 2024
1 parent 3a1c3b6 commit d5fb210
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased
## Changed
all: Use serde(default) to make the serialized strings less verbose

## Added
all: Serialized tokens can be less verbose because serde aliases were added
Expand Down
2 changes: 1 addition & 1 deletion examples/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {

// There are serde aliases so you could also deserialize the same tokens from
// the following string let serialized=r#"[t("Hello World!
// ❤\u{fe0f}"),m(10,10,r),s(5,v),b(l,c),k(uni('🔥'),c),k(ctrl,p),k(uni('a'),c),
// ❤\u{fe0f}"),m(10,10,r),s(5),b(l),k(uni('🔥')),k(ctrl,p),k(uni('a')),
// k(ctrl,r)]"#.to_string();
let serialized = ron::to_string(&tokens).unwrap();
println!("serialized = {serialized}");
Expand Down
23 changes: 18 additions & 5 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,39 @@ pub enum Token {
/// Call the [`Keyboard::key`] fn with the given key and direction
#[cfg_attr(feature = "serde", serde(alias = "K"))]
#[cfg_attr(feature = "serde", serde(alias = "k"))]
Key(Key, Direction),
Key(
Key,
#[cfg_attr(feature = "serde", serde(default))] Direction,
),
/// Call the [`Keyboard::raw`] fn with the given keycode and direction
#[cfg_attr(feature = "serde", serde(alias = "R"))]
#[cfg_attr(feature = "serde", serde(alias = "r"))]
Raw(u16, Direction),
Raw(
u16,
#[cfg_attr(feature = "serde", serde(default))] Direction,
),
/// Call the [`Mouse::button`] fn with the given mouse button and direction
#[cfg_attr(feature = "serde", serde(alias = "B"))]
#[cfg_attr(feature = "serde", serde(alias = "b"))]
Button(Button, Direction),
Button(
Button,
#[cfg_attr(feature = "serde", serde(default))] Direction,
),
/// Call the [`Mouse::move_mouse`] fn. The first i32 is the value to move on
/// the x-axis and the second i32 is the value to move on the y-axis. The
/// coordinate defines if the given coordinates are absolute of relative to
/// the current position of the mouse.
#[cfg_attr(feature = "serde", serde(alias = "M"))]
#[cfg_attr(feature = "serde", serde(alias = "m"))]
MoveMouse(i32, i32, Coordinate),
MoveMouse(
i32,
i32,
#[cfg_attr(feature = "serde", serde(default))] Coordinate,
),
/// Call the [`Mouse::scroll`] fn.
#[cfg_attr(feature = "serde", serde(alias = "S"))]
#[cfg_attr(feature = "serde", serde(alias = "s"))]
Scroll(i32, Axis),
Scroll(i32, #[cfg_attr(feature = "serde", serde(default))] Axis),
}

pub trait Agent
Expand Down

0 comments on commit d5fb210

Please sign in to comment.