-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also refactor Context public methods
- Loading branch information
Showing
7 changed files
with
75 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,65 @@ | ||
use crate::path::Path; | ||
use std::sync::Arc; | ||
|
||
use crate::path::{Path, PathArgs}; | ||
|
||
pub struct Context<S> { | ||
pub target: Option<S>, | ||
pub path: Path, | ||
pub(crate) target: Option<S>, | ||
pub(crate) path: Path, | ||
pub(crate) args: PathArgs, | ||
} | ||
|
||
impl<S> Default for Context<S> { | ||
fn default() -> Self { | ||
Context { | ||
target: None, | ||
path: Path::default(), | ||
args: PathArgs::new(), | ||
} | ||
} | ||
} | ||
|
||
impl<S> Context<S> { | ||
pub fn from_target(target: S) -> Self { | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
pub fn target(self, target: S) -> Self { | ||
Self { | ||
target: Some(target), | ||
path: Path::default(), | ||
path: self.path, | ||
args: self.args, | ||
} | ||
} | ||
|
||
pub fn with_path(self, path: &'static str) -> Self { | ||
// This will be used by the planner | ||
#[allow(dead_code)] | ||
pub(crate) fn path(self, path: &'static str) -> Self { | ||
Self { | ||
target: self.target, | ||
path: Path::from_static(path), | ||
args: self.args, | ||
} | ||
} | ||
|
||
pub fn arg(self, key: impl AsRef<str>, value: impl Into<String>) -> Self { | ||
let Self { | ||
target, | ||
path, | ||
mut args, | ||
} = self; | ||
|
||
args.0.push((Arc::from(key.as_ref()), value.into())); | ||
|
||
Self { target, path, args } | ||
} | ||
} | ||
|
||
impl<S: Clone> Clone for Context<S> { | ||
fn clone(&self) -> Self { | ||
Context { | ||
target: self.target.clone(), | ||
path: self.path.clone(), | ||
args: self.args.clone(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters