use std::future::Future;
use std::pin::Pin;
use crate::{Depth, PropertyList, SvnError};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ReportCommand {
SetPath {
path: String,
rev: u64,
start_empty: bool,
lock_token: Option<String>,
depth: Depth,
},
DeletePath {
path: String,
},
LinkPath {
path: String,
url: String,
rev: u64,
start_empty: bool,
lock_token: Option<String>,
depth: Depth,
},
FinishReport,
AbortReport,
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Report {
pub commands: Vec<ReportCommand>,
}
impl Report {
pub fn new() -> Self {
Self {
commands: Vec::new(),
}
}
pub fn push(&mut self, cmd: ReportCommand) -> &mut Self {
self.commands.push(cmd);
self
}
pub fn finish(&mut self) -> &mut Self {
self.commands.push(ReportCommand::FinishReport);
self
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum EditorEvent {
TargetRev {
rev: u64,
},
OpenRoot {
rev: Option<u64>,
token: String,
},
DeleteEntry {
path: String,
rev: u64,
dir_token: String,
},
AddDir {
path: String,
parent_token: String,
child_token: String,
copy_from: Option<(String, u64)>,
},
OpenDir {
path: String,
parent_token: String,
child_token: String,
rev: u64,
},
ChangeDirProp {
dir_token: String,
name: String,
value: Option<Vec<u8>>,
},
CloseDir {
dir_token: String,
},
AbsentDir {
path: String,
parent_token: String,
},
AddFile {
path: String,
dir_token: String,
file_token: String,
copy_from: Option<(String, u64)>,
},
OpenFile {
path: String,
dir_token: String,
file_token: String,
rev: u64,
},
ApplyTextDelta {
file_token: String,
base_checksum: Option<String>,
},
TextDeltaChunk {
file_token: String,
chunk: Vec<u8>,
},
TextDeltaEnd {
file_token: String,
},
ChangeFileProp {
file_token: String,
name: String,
value: Option<Vec<u8>>,
},
CloseFile {
file_token: String,
text_checksum: Option<String>,
},
AbsentFile {
path: String,
parent_token: String,
},
CloseEdit,
AbortEdit,
FinishReplay,
RevProps {
props: PropertyList,
},
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum EditorCommand {
OpenRoot {
rev: Option<u64>,
token: String,
},
DeleteEntry {
path: String,
rev: u64,
dir_token: String,
},
AddDir {
path: String,
parent_token: String,
child_token: String,
copy_from: Option<(String, u64)>,
},
OpenDir {
path: String,
parent_token: String,
child_token: String,
rev: u64,
},
ChangeDirProp {
dir_token: String,
name: String,
value: Option<Vec<u8>>,
},
CloseDir {
dir_token: String,
},
AbsentDir {
path: String,
parent_token: String,
},
AddFile {
path: String,
dir_token: String,
file_token: String,
copy_from: Option<(String, u64)>,
},
OpenFile {
path: String,
dir_token: String,
file_token: String,
rev: u64,
},
ApplyTextDelta {
file_token: String,
base_checksum: Option<String>,
},
TextDeltaChunk {
file_token: String,
chunk: Vec<u8>,
},
TextDeltaEnd {
file_token: String,
},
ChangeFileProp {
file_token: String,
name: String,
value: Option<Vec<u8>>,
},
CloseFile {
file_token: String,
text_checksum: Option<String>,
},
AbsentFile {
path: String,
parent_token: String,
},
CloseEdit,
AbortEdit,
}
pub trait EditorEventHandler {
fn on_event(&mut self, event: EditorEvent) -> Result<(), SvnError>;
}
pub trait AsyncEditorEventHandler: Send {
fn on_event<'a>(
&'a mut self,
event: EditorEvent,
) -> Pin<Box<dyn Future<Output = Result<(), SvnError>> + Send + 'a>>;
}