Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SunDoge committed Aug 26, 2023
1 parent 3dfd5fb commit 61c4c6c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 25 deletions.
3 changes: 1 addition & 2 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use simdjson_rust::prelude::*;
use simdjson_rust::{dom, ondemand};
use simdjson_rust::{dom, ondemand, prelude::*};

fn main() -> simdjson_rust::Result<()> {
let ps = make_padded_string("[0,1,2,3]");
Expand Down
2 changes: 1 addition & 1 deletion src/dom/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{marker::PhantomData, ptr::NonNull};

use simdjson_sys as ffi;

use super::{document::Document, element::Element, Parser};
use super::{document::Document, element::Element};
use crate::{
macros::{impl_drop, map_ptr_result},
Result,
Expand Down
16 changes: 11 additions & 5 deletions src/dom/document.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
use std::{marker::PhantomData, ptr::NonNull};
use std::ptr::NonNull;

use simdjson_sys as ffi;

use super::{Element, Parser};
use crate::{macros::impl_drop, utils::string_view_struct_to_str};
use super::Element;
use crate::macros::impl_drop;

pub struct Document {
ptr: NonNull<ffi::SJ_DOM_document>,
}

impl Document {
pub fn new() -> Self {
impl Default for Document {
fn default() -> Self {
Self {
ptr: unsafe { NonNull::new_unchecked(ffi::SJ_DOM_document_new()) },
}
}
}

impl Document {
pub fn new(ptr: NonNull<ffi::SJ_DOM_document>) -> Self {
Self { ptr }
}

pub fn root(&self) -> Element<'_> {
Element::new(unsafe {
Expand Down
3 changes: 1 addition & 2 deletions src/dom/document_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::{marker::PhantomData, ptr::NonNull};

use simdjson_sys as ffi;

use super::{Element, Parser};
use super::Element;
use crate::{
macros::{impl_drop, map_ptr_result},
utils::string_view_struct_to_str,
Result,
};

Expand Down
18 changes: 9 additions & 9 deletions src/dom/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{marker::PhantomData, ptr::NonNull};

use simdjson_sys as ffi;

use super::{array::Array, document::Document, object::Object, Parser};
use super::{array::Array, document::Document, object::Object};
use crate::{
macros::{impl_drop, map_primitive_result, map_ptr_result},
utils::string_view_struct_to_str,
Expand All @@ -11,13 +11,13 @@ use crate::{

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ElementType {
Array = '[' as _,
Object = '{' as _,
Int64 = 'l' as _,
UInt64 = 'u' as _,
Double = 'd' as _,
String = '"' as _,
Bool = 't' as _,
Array = '[' as _,
Object = '{' as _,
Int64 = 'l' as _,
UInt64 = 'u' as _,
Double = 'd' as _,
String = '"' as _,
Bool = 't' as _,
NullValue = 'n' as _,
}

Expand Down Expand Up @@ -64,7 +64,7 @@ impl<'a> Element<'a> {

pub fn get_string(&self) -> Result<&'a str> {
map_primitive_result!(ffi::SJ_DOM_element_get_string(self.ptr.as_ptr()))
.map(|sv| string_view_struct_to_str(sv))
.map(string_view_struct_to_str)
}

pub fn get_int64(&self) -> Result<i64> {
Expand Down
2 changes: 1 addition & 1 deletion src/dom/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{marker::PhantomData, ptr::NonNull};

use simdjson_sys as ffi;

use super::{document::Document, Element, Parser};
use super::{document::Document, Element};
use crate::{macros::impl_drop, utils::string_view_struct_to_str};

pub struct Object<'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/dom/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mod tests {
fn parse_into_document() {
let ps = "[1,2,3]".to_padded_string();
let parser = Parser::default();
let mut doc = Document::new();
let mut doc = Document::default();
let elem = parser.parse_into_document(&mut doc, &ps).unwrap();
assert_eq!(
elem.get_array()
Expand Down
7 changes: 3 additions & 4 deletions src/ondemand/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ impl_drop!(Document<'p, 's>, ffi::SJ_OD_document_free);

#[cfg(test)]
mod tests {
use crate::ondemand;
use crate::prelude::*;
use crate::{ondemand, prelude::*};

#[test]
fn get_bool() {
Expand All @@ -160,12 +159,12 @@ mod tests {
{
let json = "true".to_padded_string();
let mut doc = parser.iterate(&json).unwrap();
assert_eq!(doc.get_bool().unwrap(), true);
assert!(doc.get_bool().unwrap());
}
{
let json = "false".to_padded_string();
let mut doc = parser.iterate(&json).unwrap();
assert_eq!(doc.get_bool().unwrap(), false);
assert!(!doc.get_bool().unwrap());
}
{
let json = "1".to_padded_string();
Expand Down

0 comments on commit 61c4c6c

Please sign in to comment.