hg-core: remove the `Operation` trait
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.
See: rust #44265
Differential Revision: https://phab.mercurial-scm.org/D8862
--- a/rust/hg-core/src/dirstate/status.rs Tue Aug 04 10:59:43 2020 +0200
+++ b/rust/hg-core/src/dirstate/status.rs Wed Jul 29 10:08:09 2020 +0200
@@ -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::{
--- a/rust/hg-core/src/operations/dirstate_status.rs Tue Aug 04 10:59:43 2020 +0200
+++ b/rust/hg-core/src/operations/dirstate_status.rs Wed Jul 29 10:08:09 2020 +0200
@@ -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<HgPathCow<'a>>, DirstateStatus<'a>);
-impl<'a, M: Matcher + Sync> Operation<LookupAndStatus<'a>> for Status<'a, M> {
- type Error = StatusError;
-
- fn run(&self) -> Result<LookupAndStatus<'a>, Self::Error> {
+impl<'a, M: Matcher + Sync> Status<'a, M> {
+ pub(crate) fn run(&self) -> Result<LookupAndStatus<'a>, StatusError> {
let (traversed_sender, traversed_receiver) =
crossbeam::channel::unbounded();
--- a/rust/hg-core/src/operations/find_root.rs Tue Aug 04 10:59:43 2020 +0200
+++ b/rust/hg-core/src/operations/find_root.rs Wed Jul 29 10:08:09 2020 +0200
@@ -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<PathBuf> for FindRoot<'a> {
- type Error = FindRootError;
-
- fn run(&self) -> Result<PathBuf, Self::Error> {
+ pub fn run(&self) -> Result<PathBuf, FindRootError> {
let current_dir = match self.current_dir {
None => std::env::current_dir().or_else(|e| {
Err(FindRootError {
--- a/rust/hg-core/src/operations/mod.rs Tue Aug 04 10:59:43 2020 +0200
+++ b/rust/hg-core/src/operations/mod.rs Wed Jul 29 10:08:09 2020 +0200
@@ -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<T> {
- type Error;
- fn run(&self) -> Result<T, Self::Error>;
-}
+// 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.
--- a/rust/rhg/src/commands/root.rs Tue Aug 04 10:59:43 2020 +0200
+++ b/rust/rhg/src/commands/root.rs Wed Jul 29 10:08:09 2020 +0200
@@ -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;