From da76565c5d8c0ee78f5a44cb4865a0b2c715c779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Thu, 5 Dec 2024 15:07:40 +0100 Subject: [PATCH] refactor(clippy): use clippy suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- src/de.rs | 12 +++--------- src/libyaml/error.rs | 6 +++--- src/loader.rs | 5 +---- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/de.rs b/src/de.rs index 79ac4be..c101bf4 100644 --- a/src/de.rs +++ b/src/de.rs @@ -121,10 +121,7 @@ impl<'de> Deserializer<'de> { } let mut loader = Loader::new(self.progress)?; - let document = match loader.next_document() { - Some(document) => document, - None => return Err(error::new(ErrorImpl::EndOfStream)), - }; + let Some(document) = loader.next_document() else { return Err(error::new(ErrorImpl::EndOfStream)) }; let t = f(&mut DeserializerFromEvents { document: &document, pos: &mut pos, @@ -859,15 +856,12 @@ fn visit_scalar<'de, V>(visitor: V, scalar: &Scalar<'de>, tagged_already: bool) where V: Visitor<'de>, { - let v = match str::from_utf8(&scalar.value) { - Ok(v) => v, - Err(_) => { + let Ok(v) = str::from_utf8(&scalar.value) else { return Err(de::Error::invalid_type( Unexpected::Bytes(&scalar.value), &visitor, )) - } - }; + }; if let (Some(tag), false) = (&scalar.tag, tagged_already) { if tag == Tag::BOOL { return match parse_bool(v) { diff --git a/src/libyaml/error.rs b/src/libyaml/error.rs index 8397f6e..e0cbe59 100644 --- a/src/libyaml/error.rs +++ b/src/libyaml/error.rs @@ -19,7 +19,7 @@ impl Error { pub unsafe fn parse_error(parser: *const sys::yaml_parser_t) -> Self { Error { kind: unsafe { (*parser).error }, - problem: match NonNull::new(unsafe { (*parser).problem as *mut _ }) { + problem: match NonNull::new(unsafe { (*parser).problem.cast_mut() }) { Some(problem) => unsafe { CStr::from_ptr(problem) }, None => CStr::from_bytes_with_nul(b"libyaml parser failed but there is no error\0"), }, @@ -27,7 +27,7 @@ impl Error { problem_mark: Mark { sys: unsafe { (*parser).problem_mark }, }, - context: match NonNull::new(unsafe { (*parser).context as *mut _ }) { + context: match NonNull::new(unsafe { (*parser).context.cast_mut() }) { Some(context) => Some(unsafe { CStr::from_ptr(context) }), None => None, }, @@ -40,7 +40,7 @@ impl Error { pub unsafe fn emit_error(emitter: *const sys::yaml_emitter_t) -> Self { Error { kind: unsafe { (*emitter).error }, - problem: match NonNull::new(unsafe { (*emitter).problem as *mut _ }) { + problem: match NonNull::new(unsafe { (*emitter).problem.cast_mut() }) { Some(problem) => unsafe { CStr::from_ptr(problem) }, None => { CStr::from_bytes_with_nul(b"libyaml emitter failed but there is no error\0") diff --git a/src/loader.rs b/src/loader.rs index 7c7c7b6..0ba4d13 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -41,10 +41,7 @@ impl<'input> Loader<'input> { } pub fn next_document(&mut self) -> Option> { - let parser = match &mut self.parser { - Some(parser) => parser, - None => return None, - }; + let Some(parser) = &mut self.parser else { return None }; let first = self.document_count == 0; self.document_count += 1;