diff --git a/rust/hg-core/src/dirstate/status.rs b/rust/hg-core/src/dirstate/status.rs --- a/rust/hg-core/src/dirstate/status.rs +++ b/rust/hg-core/src/dirstate/status.rs @@ -13,7 +13,6 @@ dirstate::SIZE_FROM_OTHER_PARENT, filepatterns::PatternFileWarning, matchers::{get_ignore_function, Matcher, VisitChildrenSet}, - operations::Operation, utils::{ files::{find_dirs, HgMetadata}, hg_path::{ diff --git a/rust/hg-core/src/operations/dirstate_status.rs b/rust/hg-core/src/operations/dirstate_status.rs --- a/rust/hg-core/src/operations/dirstate_status.rs +++ b/rust/hg-core/src/operations/dirstate_status.rs @@ -7,7 +7,6 @@ use crate::dirstate::status::{build_response, Dispatch, HgPathCow, Status}; use crate::matchers::Matcher; -use crate::operations::Operation; use crate::{DirstateStatus, StatusError}; /// A tuple of the paths that need to be checked in the filelog because it's @@ -15,10 +14,8 @@ /// files. pub type LookupAndStatus<'a> = (Vec>, DirstateStatus<'a>); -impl<'a, M: Matcher + Sync> Operation> for Status<'a, M> { - type Error = StatusError; - - fn run(&self) -> Result, Self::Error> { +impl<'a, M: Matcher + Sync> Status<'a, M> { + pub(crate) fn run(&self) -> Result, StatusError> { let (traversed_sender, traversed_receiver) = crossbeam::channel::unbounded(); diff --git a/rust/hg-core/src/operations/find_root.rs b/rust/hg-core/src/operations/find_root.rs --- a/rust/hg-core/src/operations/find_root.rs +++ b/rust/hg-core/src/operations/find_root.rs @@ -1,4 +1,3 @@ -use super::Operation; use std::fmt; use std::path::{Path, PathBuf}; @@ -45,12 +44,8 @@ current_dir: Some(current_dir), } } -} -impl<'a> Operation for FindRoot<'a> { - type Error = FindRootError; - - fn run(&self) -> Result { + pub fn run(&self) -> Result { let current_dir = match self.current_dir { None => std::env::current_dir().or_else(|e| { Err(FindRootError { diff --git a/rust/hg-core/src/operations/mod.rs b/rust/hg-core/src/operations/mod.rs --- a/rust/hg-core/src/operations/mod.rs +++ b/rust/hg-core/src/operations/mod.rs @@ -1,13 +1,13 @@ +//! A distinction is made between operations and commands. +//! An operation is what can be done whereas a command is what is exposed by +//! the cli. A single command can use several operations to achieve its goal. + mod dirstate_status; mod find_root; pub use find_root::{FindRoot, FindRootError, FindRootErrorKind}; -/// An interface for high-level hg operations. -/// -/// A distinction is made between operation and commands. -/// An operation is what can be done whereas a command is what is exposed by -/// the cli. A single command can use several operations to achieve its goal. -pub trait Operation { - type Error; - fn run(&self) -> Result; -} +// TODO add an `Operation` trait when GAT have landed (rust #44265): +// there is no way to currently define a trait which can both return +// references to `self` and to passed data, which is what we would need. +// Generic Associated Types may fix this and allow us to have a unified +// interface. diff --git a/rust/rhg/src/commands/root.rs b/rust/rhg/src/commands/root.rs --- a/rust/rhg/src/commands/root.rs +++ b/rust/rhg/src/commands/root.rs @@ -1,7 +1,7 @@ use crate::commands::Command; use crate::error::{CommandError, CommandErrorKind}; use crate::ui::Ui; -use hg::operations::{FindRoot, FindRootError, FindRootErrorKind, Operation}; +use hg::operations::{FindRoot, FindRootError, FindRootErrorKind}; use hg::utils::files::get_bytes_from_path; use std::path::PathBuf;