Skip to main content

vvv_engine/protocol/intent/
mod.rs

1//! What the user wants done, as data.
2//!
3//! An intent is built by the CLI from arguments, by a TUI from a form, or by
4//! a client from JSON, and handed to the engine. Nothing here knows how the
5//! intent is fulfilled.
6
7mod batch;
8mod move_file;
9mod move_symbol;
10mod rename;
11mod rewrite;
12
13use serde::{Deserialize, Serialize};
14
15pub use batch::BatchIntent;
16pub use move_file::MoveIntent;
17pub use move_symbol::MoveSymbolIntent;
18pub use rename::RenameIntent;
19pub use rewrite::{RewriteIntent, RewriteOf};
20
21/// Any mutating request, as one value: what history records, what a summary
22/// renders, what a remote client sends.
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
24#[serde(tag = "command", rename_all = "snake_case")]
25pub enum Intent {
26    Rewrite(RewriteIntent),
27    Rename(RenameIntent),
28    Move(MoveIntent),
29    MoveSymbol(MoveSymbolIntent),
30    /// Several intents planned in sequence, each against the state the
31    /// previous one leaves, and applied as one.
32    Batch(BatchIntent),
33}
34
35impl From<BatchIntent> for Intent {
36    fn from(i: BatchIntent) -> Self {
37        Self::Batch(i)
38    }
39}
40
41impl From<RewriteIntent> for Intent {
42    fn from(i: RewriteIntent) -> Self {
43        Self::Rewrite(i)
44    }
45}
46
47impl From<RenameIntent> for Intent {
48    fn from(i: RenameIntent) -> Self {
49        Self::Rename(i)
50    }
51}
52
53impl From<MoveIntent> for Intent {
54    fn from(i: MoveIntent) -> Self {
55        Self::Move(i)
56    }
57}
58
59impl From<MoveSymbolIntent> for Intent {
60    fn from(i: MoveSymbolIntent) -> Self {
61        Self::MoveSymbol(i)
62    }
63}