mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-21 02:20:44 +08:00
radicle-git init
Port over all git relevant parts of the radicle-link repository[0]. The packages that are kept are: * git-ext * git-ref-format * git-trailers * link-git * macros * std-ext * test -- only the portions that test the above The development and testing scripts are also added for local and CI testing. [0]: https://github.com/radicle-dev/radicle-link/ Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// Copyright © 2019-2020 The Radicle Foundation <hello@radicle.foundation>
|
||||
//
|
||||
// This file is part of radicle-link, distributed under the GPLv3 with Radicle
|
||||
// Linking Exception. For full terms see the included LICENSE file.
|
||||
|
||||
use std::{
|
||||
io,
|
||||
ops::{Deref, DerefMut},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use tempfile::{tempdir, TempDir};
|
||||
|
||||
pub struct WithTmpDir<A> {
|
||||
_tmp: TempDir,
|
||||
inner: A,
|
||||
}
|
||||
|
||||
impl<A> WithTmpDir<A> {
|
||||
pub fn new<F, E>(mk_inner: F) -> Result<Self, E>
|
||||
where
|
||||
F: FnOnce(&Path) -> Result<A, E>,
|
||||
E: From<io::Error>,
|
||||
{
|
||||
let tmp = tempdir()?;
|
||||
let inner = mk_inner(tmp.path())?;
|
||||
Ok(Self { _tmp: tmp, inner })
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> Deref for WithTmpDir<A> {
|
||||
type Target = A;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> DerefMut for WithTmpDir<A> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user