acezar created this revision. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches.
REVISION SUMMARY 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 REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D8862 AFFECTED FILES rust/hg-core/src/dirstate/status.rs rust/hg-core/src/operations/dirstate_status.rs rust/hg-core/src/operations/find_root.rs rust/hg-core/src/operations/mod.rs rust/rhg/src/commands/root.rs CHANGE DETAILS 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; 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<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. 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<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 { 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<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(); 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::{ To: acezar, #hg-reviewers Cc: mercurial-patches, mercurial-devel _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel