sapling/eden/scm/edenscmnative
David Tolnay 066f461bcf Replace reliance on From<Context<_>> with an extension trait and constructor
Summary:
Edenapi uses a group of impls like the following as the canonical way to construct ApiError.

```
impl From<Context<ApiErrorKind>> for ApiError {
```

Downstream code would write:

```
use failure::ResultExt;

let stream_trees = config
    .get_or_default("edenapi", "streamtrees")
    .context(ApiErrorKind::BadConfig("edenapi.streamtrees"))?;
```

This relies on the way that ResultExt::context returns a unique type that is different from failure::Error.

This diff introduces a dedicated extension trait to allow the same code in the caller to continue to work even without a failure::Context<T> type, which will be required for dropping our dependency on failure::Fail and failure.

```
pub trait ApiErrorContext<T> {
    fn context(self, kind: ApiErrorKind) -> ApiResult<T>;
}
```

We also introduce a public constructor for ApiError and replace indirect construction that used to look like this:

```
error.context(ApiErrorKind::Curl).into()
```

with this instead:

```
ApiError::new(ApiErrorKind::Curl, error)
```

which is the same number of characters but clearer. The argument order matches [std::io::Error::new](https://doc.rust-lang.org/std/io/struct.Error.html#method.new).

Reviewed By: kulshrax

Differential Revision: D18574668

fbshipit-source-id: 0a56297bb942a26d75a62ca39fc16abeb4486345
2019-11-18 12:12:43 -08:00
..
bindings Replace reliance on From<Context<_>> with an extension trait and constructor 2019-11-18 12:12:43 -08:00
__init__.py Move fb-mercurial sources into an eden/scm subdirectory. 2019-11-13 16:04:48 -08:00
clindex.pyx Move fb-mercurial sources into an eden/scm subdirectory. 2019-11-13 16:04:48 -08:00
linelog.pyx Move fb-mercurial sources into an eden/scm subdirectory. 2019-11-13 16:04:48 -08:00
patchrmdir.pyx Move fb-mercurial sources into an eden/scm subdirectory. 2019-11-13 16:04:48 -08:00
traceprof.pyx Move fb-mercurial sources into an eden/scm subdirectory. 2019-11-13 16:04:48 -08:00