From fbaa41611d2aa30815a3d9d3c214698825bc6896 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 18 Nov 2021 00:14:48 +0100 Subject: driver: context: avoid double reference in Index impl Make lifetimes around the get() method less strict to avoid an unnecessary double reference. --- crates/driver/src/context.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'crates/driver/src/context.rs') 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> for error::Error { +impl<'a> From> for error::Error { fn from(err: Error) -> Self { error::Error::new(err) } } -pub type Result<'ctx, T> = result::Result>; +pub type Result<'a, T> = result::Result>; #[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") } } -- cgit v1.2.3