comparison rust/hg-core/src/operations/find_root.rs @ 45358:452ece5654c5

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
author Antoine Cezar <antoine.cezar@octobus.net>
date Wed, 29 Jul 2020 10:08:09 +0200
parents 5965efb609b6
children 3d9f1dfc52c2
comparison
equal deleted inserted replaced
45357:27424779c5b8 45358:452ece5654c5
1 use super::Operation;
2 use std::fmt; 1 use std::fmt;
3 use std::path::{Path, PathBuf}; 2 use std::path::{Path, PathBuf};
4 3
5 /// Kind of error encoutered by FindRoot 4 /// Kind of error encoutered by FindRoot
6 #[derive(Debug)] 5 #[derive(Debug)]
43 pub fn new_from_path(current_dir: &'a Path) -> Self { 42 pub fn new_from_path(current_dir: &'a Path) -> Self {
44 Self { 43 Self {
45 current_dir: Some(current_dir), 44 current_dir: Some(current_dir),
46 } 45 }
47 } 46 }
48 }
49 47
50 impl<'a> Operation<PathBuf> for FindRoot<'a> { 48 pub fn run(&self) -> Result<PathBuf, FindRootError> {
51 type Error = FindRootError;
52
53 fn run(&self) -> Result<PathBuf, Self::Error> {
54 let current_dir = match self.current_dir { 49 let current_dir = match self.current_dir {
55 None => std::env::current_dir().or_else(|e| { 50 None => std::env::current_dir().or_else(|e| {
56 Err(FindRootError { 51 Err(FindRootError {
57 kind: FindRootErrorKind::GetCurrentDirError(e), 52 kind: FindRootErrorKind::GetCurrentDirError(e),
58 }) 53 })