Skip to content

Commit

Permalink
refactor(clippy): use clippy suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Christina Sørensen <[email protected]>
  • Loading branch information
cafkafk committed Dec 5, 2024
1 parent 4ca6930 commit da76565
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
12 changes: 3 additions & 9 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/libyaml/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ 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"),
},
problem_offset: unsafe { (*parser).problem_offset },
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,
},
Expand All @@ -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")
Expand Down
5 changes: 1 addition & 4 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ impl<'input> Loader<'input> {
}

pub fn next_document(&mut self) -> Option<Document<'input>> {
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;
Expand Down

0 comments on commit da76565

Please sign in to comment.