|
@@ -105,41 +105,53 @@ impl PatchPen {
|
|
|
pub struct ClonePen {
|
|
|
from: usize,
|
|
|
to: usize,
|
|
|
+ inclusive: Option<bool>,
|
|
|
#[serde(flatten)]
|
|
|
patch: Option<Patch>,
|
|
|
}
|
|
|
|
|
|
impl ClonePen {
|
|
|
- pub fn clone_single(&self, pens: &mut Vec<Pen>) {
|
|
|
- debug!("Cloning pen #{} to #{}", self.from, self.to);
|
|
|
+ pub fn clone(&self, pens: &mut Vec<Pen>) {
|
|
|
+ debug!(
|
|
|
+ "Cloning pen #{} to #{}{}",
|
|
|
+ self.from,
|
|
|
+ self.to,
|
|
|
+ match self.inclusive {
|
|
|
+ Some(true) => format!("(inclusive)"),
|
|
|
+ _ => format!(""),
|
|
|
+ }
|
|
|
+ );
|
|
|
|
|
|
// Clone pen
|
|
|
let src: Pen = pens.get(self.from).expect("Invalid pen index").clone();
|
|
|
- let dst: &mut Pen = pens.get_mut(self.to).expect("Invalid pen index");
|
|
|
- *dst = src;
|
|
|
|
|
|
- // Patch pen if needed
|
|
|
- if let Some(patch) = &self.patch {
|
|
|
- patch.patch(self.to, pens);
|
|
|
- }
|
|
|
- }
|
|
|
+ match self.inclusive {
|
|
|
+ Some(true) => {
|
|
|
+ assert!(
|
|
|
+ self.to > self.from,
|
|
|
+ "Target pen(s) must be greater than source pen"
|
|
|
+ );
|
|
|
|
|
|
- pub fn clone_range(&self, pens: &mut Vec<Pen>) {
|
|
|
- debug!(
|
|
|
- "Cloning pen #{} to #{} (and all in between)",
|
|
|
- self.from, self.to
|
|
|
- );
|
|
|
- assert!(
|
|
|
- self.to > self.from,
|
|
|
- "Target pen(s) must be greater than source pen"
|
|
|
- );
|
|
|
+ // Clone pen
|
|
|
+ for idx in (self.from..=self.to).skip(1) {
|
|
|
+ let dst: &mut Pen = pens.get_mut(idx).expect("Invalid pen index");
|
|
|
+ *dst = src.clone();
|
|
|
|
|
|
- // Clone pen
|
|
|
- let src: Pen = pens.get(self.from).expect("Invalid pen index").clone();
|
|
|
+ // Patch pen if needed
|
|
|
+ if let Some(patch) = &self.patch {
|
|
|
+ patch.patch(idx, pens);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _ => {
|
|
|
+ let dst: &mut Pen = pens.get_mut(self.to).expect("Invalid pen index");
|
|
|
+ *dst = src;
|
|
|
|
|
|
- for idx in (self.from..=self.to).skip(1) {
|
|
|
- let dst: &mut Pen = pens.get_mut(idx).expect("Invalid pen index");
|
|
|
- *dst = src.clone();
|
|
|
+ // Patch pen if needed
|
|
|
+ if let Some(patch) = &self.patch {
|
|
|
+ patch.patch(self.to, pens);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|