Skip to content

Commit

Permalink
fixed a bunch of warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Sep 29, 2020
1 parent 89271e3 commit df6b12c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/bin/foliabenchmarkr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Rusage(libc::rusage);
pub type Errno = os::raw::c_int;

fn get_resource_usage(who: os::raw::c_int) -> Result<libc::rusage, Errno> {
let mut data = unsafe { mem::uninitialized() };
let mut data = unsafe { mem::MaybeUninit::uninit().assume_init() };

let result = unsafe { libc::getrusage(who, &mut data) };

Expand Down Expand Up @@ -106,6 +106,7 @@ fn test(test_id: &str, filename: &str) {
for _element in doc.select(selector, Recursion::Always) {
count += 1;
}
println!("{}",count);
m.end(test_id, filename, "Parse XML from file into full memory representation");
doc.id(); //just to make sure the compiler doesn't optimise doc away (not sure if needed but better safe than sorry)
},
Expand Down
4 changes: 2 additions & 2 deletions src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl Document {
}
}
if let Some(prockey) = self.active_processor {
if let Some(mut declaration) = self.get_mut_declaration(declaration_key.expect("get deckey")) {
if let Some(declaration) = self.get_mut_declaration(declaration_key.expect("get deckey")) {
if !declaration.processors.contains(&prockey) {
declaration.processors.push(prockey);
}
Expand Down Expand Up @@ -826,7 +826,7 @@ impl Store<ElementData,ElementKey> for Document {

let annotationtype = parent.elementtype.annotationtype().expect(format!("Unwrapping annotation type of parent {}", element.elementtype).as_str() );
let deckey = self.declare(annotationtype, &element.set().unwrap().map(|s| s.to_string()), &None, &None)?;
declaration_key = Some(deckey);;
declaration_key = Some(deckey);

if let Some(declaration) = self.get_mut_declaration(deckey) {
if let Ok(Some(class)) = element.class() {
Expand Down
11 changes: 7 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ impl From<quick_xml::Error> for FoliaError {
}
}

impl Error for FoliaError {
fn description(&self) -> &str {
impl FoliaError {
fn as_str(&self) -> &str {
match *self {
FoliaError::IoError(ref err) => err.description(),
FoliaError::IoError(ref _err) => "IO Error",
FoliaError::XmlError(ref _err) => "XML Error",
FoliaError::ParseError(ref _err) => "Parse Error",
FoliaError::SerialisationError(ref _err) => "Serialisation Error",
Expand All @@ -96,6 +96,9 @@ impl Error for FoliaError {
FoliaError::IndexError => "invalid index",
}
}
}

impl Error for FoliaError {

fn cause(&self) -> Option<&dyn Error> {
match *self {
Expand Down Expand Up @@ -131,7 +134,7 @@ impl fmt::Display for FoliaError {
FoliaError::QueryError(ref err) |
FoliaError::TypeError(ref err) |
FoliaError::KeyError(ref err) => {
write!(f, "[{}] {}", self.description(), err)
write!(f, "[{}] {}", self.as_str(), err)
}
FoliaError::IndexError => fmt::Display::fmt("invalid index", f),
}
Expand Down
4 changes: 2 additions & 2 deletions src/serialiser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl Document {
let mut last_start: String = "<ROOT>".to_string();
for item in self.select_data_by_key(root_key,Selector::all_data(),Recursion::Always, true, false) {
while item.depth < previous_depth {
if let Some((end,elementtype,tagstring)) = stack.pop() {
if let Some((end,elementtype,_tagstring)) = stack.pop() {
writer.write_event(Event::End(end)).map_err(to_serialisation_error)?;
if !ElementGroup::TextMarkup.contains(elementtype) {
writer.write_event(Event::Text(BytesText::from_plain(NL))).map_err(to_serialisation_error)?;
Expand Down Expand Up @@ -300,7 +300,7 @@ impl Document {
}

//don't forget the final closing elements
while let Some((end, _elementtype, tagstring)) = stack.pop() {
while let Some((end, _elementtype, _tagstring)) = stack.pop() {
writer.write_event(Event::End(end)).map_err(to_serialisation_error)?;
//eprintln!("[DEBUG] <-- Popped final end tag {}", tagstring.as_str());
}
Expand Down
4 changes: 2 additions & 2 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait Storable<Key> {
}

///Set the key of the current item (if supported by the item)
fn assign_key(&mut self, key: Key) {
fn assign_key(&mut self, _key: Key) {
//does nothing by default, override in implementations
}

Expand All @@ -49,7 +49,7 @@ pub trait Store<T,Key> where T: Storable<Key>,
fn iter(&self) -> std::slice::Iter<Option<Box<T>>>;
fn index(&self) -> &HashMap<String,Key>;

fn encode(&mut self, mut item: T, context: Option<Key>) -> Result<T,FoliaError> {
fn encode(&mut self, item: T, _context: Option<Key>) -> Result<T,FoliaError> {
Ok(item) //we assume the item does not need to be decoded by default
}

Expand Down
1 change: 0 additions & 1 deletion src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ impl<'a> Element<'a> {
///Returns the text content of a given element
pub fn text_by_key(&self, set: DecKey, textclass: ClassKey, strict: bool, retaintokenisation: bool, previousdelimiter: Option<String>) -> Result<String,FoliaError> {
let doc = self.document().ok_or(FoliaError::KeyError("Element has no associated document".to_string()))?;
let key = self.key().ok_or(FoliaError::KeyError("Element has no key".to_string()))?;

let properties = doc.props(self.elementtype());

Expand Down

0 comments on commit df6b12c

Please sign in to comment.