summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-11-18 00:14:48 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-11-18 00:14:48 +0100
commitfbaa41611d2aa30815a3d9d3c214698825bc6896 (patch)
tree4cc73e98e8b80fd5470482175de7ab23b8fd8247
parentac59d9359ddc1e9bcc15240a5d26833c12d86f5e (diff)
downloadrebel-fbaa41611d2aa30815a3d9d3c214698825bc6896.tar
rebel-fbaa41611d2aa30815a3d9d3c214698825bc6896.zip
driver: context: avoid double reference in Index impl
Make lifetimes around the get() method less strict to avoid an unnecessary double reference.
-rw-r--r--crates/driver/src/context.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/crates/driver/src/context.rs b/crates/driver/src/context.rs
index 2f29aed..70c4556 100644
--- a/crates/driver/src/context.rs
+++ b/crates/driver/src/context.rs
@@ -24,19 +24,19 @@ use crate::{
};
#[derive(Debug, Clone, Copy)]
-pub enum ErrorKind<'ctx> {
+pub enum ErrorKind<'a> {
TaskNotFound,
- InvalidArgument(&'ctx str),
- InvalidArgRef(&'ctx str),
+ InvalidArgument(&'a str),
+ InvalidArgRef(&'a str),
}
#[derive(Debug, Clone, Copy)]
-pub struct Error<'ctx> {
- pub task: &'ctx TaskID,
- pub kind: ErrorKind<'ctx>,
+pub struct Error<'a> {
+ pub task: &'a TaskID,
+ pub kind: ErrorKind<'a>,
}
-impl<'ctx> Display for Error<'ctx> {
+impl<'a> Display for Error<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Error { task, kind } = self;
match kind {
@@ -55,13 +55,13 @@ impl<'ctx> Display for Error<'ctx> {
}
}
-impl<'ctx> From<Error<'ctx>> for error::Error {
+impl<'a> From<Error<'a>> for error::Error {
fn from(err: Error) -> Self {
error::Error::new(err)
}
}
-pub type Result<'ctx, T> = result::Result<T, Error<'ctx>>;
+pub type Result<'a, T> = result::Result<T, Error<'a>>;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct TaskRef<'ctx> {
@@ -293,7 +293,7 @@ impl Context {
.max_by(|task1, task2| Self::compare_tasks(task1, task2))
}
- fn get_with_args<'ctx>(&'ctx self, id: &'ctx TaskID, args: &TaskArgs) -> Result<&TaskDef> {
+ fn get_with_args<'a>(&self, id: &'a TaskID, args: &TaskArgs) -> Result<'a, &TaskDef> {
self.tasks
.get(id)
.and_then(|tasks| Self::select_task(tasks, args))
@@ -303,7 +303,7 @@ impl Context {
})
}
- pub fn get<'ctx>(&'ctx self, task: &TaskRef<'ctx>) -> Result<&TaskDef> {
+ pub fn get<'a>(&self, task: &TaskRef<'a>) -> Result<'a, &TaskDef> {
self.get_with_args(task.id, task.args.as_ref())
}
@@ -520,10 +520,10 @@ impl Context {
}
}
-impl<'ctx> Index<&TaskRef<'ctx>> for &'ctx Context {
+impl Index<&TaskRef<'_>> for Context {
type Output = TaskDef;
- fn index(&self, index: &TaskRef<'ctx>) -> &TaskDef {
+ fn index(&self, index: &TaskRef) -> &TaskDef {
self.get(index).expect("Invalid TaskRef")
}
}