diff --git a/src/input/input_abstract.rs b/src/input/input_abstract.rs index e84c132df..17c9546db 100644 --- a/src/input/input_abstract.rs +++ b/src/input/input_abstract.rs @@ -85,7 +85,7 @@ pub trait Input<'py>: fmt::Debug { fn validate_dataclass_args<'a>(&'a self, dataclass_name: &str) -> ValResult>; - fn validate_str(&self, strict: bool, coerce_numbers_to_str: bool) -> ValMatch>; + fn validate_str(&self, strict: bool, coerce_numbers_to_str: bool) -> ValMatch>; fn validate_bytes<'a>(&'a self, strict: bool, mode: ValBytesMode) -> ValMatch>; @@ -103,7 +103,7 @@ pub trait Input<'py>: fmt::Debug { /// Extract a String from the input, only allowing exact /// matches for a String (no subclasses) - fn exact_str(&self) -> ValResult> { + fn exact_str(&self) -> ValResult> { self.validate_str(true, false).and_then(|val_match| { val_match .require_exact() diff --git a/src/input/input_json.rs b/src/input/input_json.rs index 27a710058..b66de5395 100644 --- a/src/input/input_json.rs +++ b/src/input/input_json.rs @@ -107,7 +107,11 @@ impl<'py, 'data> Input<'py> for JsonValue<'data> { } } - fn validate_str(&self, strict: bool, coerce_numbers_to_str: bool) -> ValResult>> { + fn validate_str( + &self, + strict: bool, + coerce_numbers_to_str: bool, + ) -> ValResult>> { // Justification for `strict` instead of `exact` is that in JSON strings can also // represent other datatypes such as UUID and date more exactly, so string is a // converting input @@ -163,7 +167,7 @@ impl<'py, 'data> Input<'py> for JsonValue<'data> { } } - fn exact_str(&self) -> ValResult> { + fn exact_str(&self) -> ValResult> { match self { JsonValue::Str(s) => Ok(s.as_ref().into()), _ => Err(ValError::new(ErrorTypeDefaults::StringType, self)), @@ -414,7 +418,7 @@ impl<'py> Input<'py> for str { &self, _strict: bool, _coerce_numbers_to_str: bool, - ) -> ValResult>> { + ) -> ValResult>> { // Justification for `strict` instead of `exact` is that in JSON strings can also // represent other datatypes such as UUID and date more exactly, so string is a // converting input diff --git a/src/input/input_python.rs b/src/input/input_python.rs index 568c5e08d..0f4ceb672 100644 --- a/src/input/input_python.rs +++ b/src/input/input_python.rs @@ -163,7 +163,11 @@ impl<'py> Input<'py> for Bound<'py, PyAny> { } } - fn validate_str(&self, strict: bool, coerce_numbers_to_str: bool) -> ValResult>> { + fn validate_str( + &self, + strict: bool, + coerce_numbers_to_str: bool, + ) -> ValResult>> { if let Ok(py_str) = self.downcast_exact::() { return Ok(ValidationMatch::exact(py_str.clone().into())); } else if let Ok(py_str) = self.downcast::() { @@ -310,7 +314,7 @@ impl<'py> Input<'py> for Bound<'py, PyAny> { } } - fn exact_str(&self) -> ValResult> { + fn exact_str(&self) -> ValResult> { if let Ok(py_str) = self.downcast_exact() { Ok(EitherString::Py(py_str.clone())) } else { diff --git a/src/input/input_string.rs b/src/input/input_string.rs index 97fb17a3d..a635188a8 100644 --- a/src/input/input_string.rs +++ b/src/input/input_string.rs @@ -105,7 +105,7 @@ impl<'py> Input<'py> for StringMapping<'py> { &self, _strict: bool, _coerce_numbers_to_str: bool, - ) -> ValResult>> { + ) -> ValResult>> { match self { Self::String(s) => Ok(ValidationMatch::strict(s.clone().into())), Self::Mapping(_) => Err(ValError::new(ErrorTypeDefaults::StringType, self)), diff --git a/src/input/return_enums.rs b/src/input/return_enums.rs index 221b76e21..526d2c970 100644 --- a/src/input/return_enums.rs +++ b/src/input/return_enums.rs @@ -468,20 +468,20 @@ impl<'data> GenericJsonIterator<'data> { } #[cfg_attr(debug_assertions, derive(Debug))] -pub enum EitherString<'a> { +pub enum EitherString<'a, 'py> { Cow(Cow<'a, str>), - Py(Bound<'a, PyString>), + Py(Bound<'py, PyString>), } -impl<'a> EitherString<'a> { +impl<'py> EitherString<'_, 'py> { pub fn as_cow(&self) -> ValResult> { match self { - Self::Cow(data) => Ok(data.clone()), + Self::Cow(data) => Ok(Cow::Borrowed(data)), Self::Py(py_str) => Ok(Cow::Borrowed(py_string_str(py_str)?)), } } - pub fn as_py_string(&'a self, py: Python<'a>, cache_str: StringCacheMode) -> Bound<'a, PyString> { + pub fn as_py_string(&self, py: Python<'py>, cache_str: StringCacheMode) -> Bound<'py, PyString> { match self { Self::Cow(cow) => new_py_string(py, cow.as_ref(), cache_str), Self::Py(py_string) => py_string.clone(), @@ -489,20 +489,20 @@ impl<'a> EitherString<'a> { } } -impl<'a> From<&'a str> for EitherString<'a> { +impl<'a> From<&'a str> for EitherString<'a, '_> { fn from(data: &'a str) -> Self { Self::Cow(Cow::Borrowed(data)) } } -impl From for EitherString<'_> { +impl From for EitherString<'_, '_> { fn from(data: String) -> Self { Self::Cow(Cow::Owned(data)) } } -impl<'a> From> for EitherString<'a> { - fn from(date: Bound<'a, PyString>) -> Self { +impl<'py> From> for EitherString<'_, 'py> { + fn from(date: Bound<'py, PyString>) -> Self { Self::Py(date) } }