From: Ian Jackson Date: Sun, 15 May 2022 11:05:33 +0000 (+0100) Subject: subst: Break out Substituting::err X-Git-Tag: otter-1.1.0~130 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=93ae50f082113b94d1d8084f52b784a3ba50a500;p=otter.git subst: Break out Substituting::err We're going to want to reuse this. Signed-off-by: Ian Jackson --- diff --git a/src/shapelib.rs b/src/shapelib.rs index bd608f7a..8f3908dc 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -1058,6 +1058,10 @@ impl<'s> Substituting<'s> { pub fn nest(self) -> String { self.s.into() } + + fn err(&self, kind: SubstErrorKind) -> SubstError { + SubstError { kind, input: (*self.s).to_owned() } + } } #[throws(SubstError)] @@ -1125,10 +1129,9 @@ fn subst_general<'i>(input: &Substituting<'i>, fn subst<'i>(before: Substituting<'i>, needle: &'static str, replacement: &str) -> Substituting<'i> { use SubstErrorKind as SEK; - let err = |kind| SubstError { kind, input: (*before.s).to_owned() }; let (out, count) = subst_general(&before, needle, replacement)?; - if count == 0 { throw!(err(SEK::MissingToken(needle))) } - if count > 1 { throw!(err(SEK::RepeatedToken(needle))) } + if count == 0 { throw!(before.err(SEK::MissingToken(needle))) } + if count > 1 { throw!(before.err(SEK::RepeatedToken(needle))) } out }