Skip to content

Commit

Permalink
Bump derive_builder from 0.9 to 0.12 (#1129)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Hvaara authored and Narsil committed Jan 16, 2023
1 parent 6bb7d84 commit f60508e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bindings/node/native/src/processors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn template_processing(mut cx: FunctionContext) -> JsResult<JsPostProcessor> {
if let Some(pair) = pair {
builder.try_pair(pair).map_err(Error)?;
}
let processor = builder.build().map_err(Error)?;
let processor = builder.build().map_err(|e| Error(e.to_string()))?;

let mut js_processor = JsPostProcessor::new::<_, JsPostProcessor, _>(&mut cx, vec![])?;
let guard = cx.lock();
Expand Down
4 changes: 3 additions & 1 deletion bindings/python/src/processors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ impl PyTemplateProcessing {
if let Some(sp) = special_tokens {
builder.special_tokens(sp);
}
let processor = builder.build().map_err(exceptions::PyValueError::new_err)?;
let processor = builder
.build()
.map_err(|e| exceptions::PyValueError::new_err(e.to_string()))?;

Ok((
PyTemplateProcessing {},
Expand Down
2 changes: 1 addition & 1 deletion tokenizers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ unicode-segmentation = "1.6"
indicatif = {version = "0.15", optional = true}
itertools = "0.9"
log = "0.4"
derive_builder = "0.9"
derive_builder = "0.12"
spm_precompiled = "0.1"
dirs = "3.0"
reqwest = { version = "0.11", optional = true }
Expand Down
26 changes: 26 additions & 0 deletions tokenizers/src/processors/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ pub struct TemplateProcessing {
special_tokens: Tokens,
}

impl From<&str> for TemplateProcessingBuilderError {
fn from(e: &str) -> Self {
e.to_string().into()
}
}

impl PartialEq for TemplateProcessingBuilderError {
fn eq(&self, other: &Self) -> bool {
self.to_string() == other.to_string()
}
}

/// We use this custom deserializer to provided the values for `added_single`
/// and `added_pair` during deserialization, while not having to serialize them
#[doc(hidden)]
Expand Down Expand Up @@ -1074,4 +1086,18 @@ mod tests {
Err("Template for `pair` must use both sequences".into())
);
}

#[test]
fn expect_wrong_error_message() {
let processor = TemplateProcessing::builder()
.try_single("$0")
.unwrap()
.try_pair("$0 $1")
.unwrap()
.build();
assert_ne!(
processor,
Err("Expect the left side error message to be different from the right side!".into())
);
}
}

0 comments on commit f60508e

Please sign in to comment.