Skip to content

Commit

Permalink
Added umisc types for fields. Issue google#141
Browse files Browse the repository at this point in the history
  • Loading branch information
filmil committed Jun 23, 2020
1 parent 8cd61ec commit da87413
Show file tree
Hide file tree
Showing 11 changed files with 1,947 additions and 27 deletions.
24 changes: 24 additions & 0 deletions rust_icu_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//! At the moment, this crate contains the declaration of various errors
use {
anyhow::anyhow,
rust_icu_sys as sys,
std::{ffi, os},
thiserror::Error,
Expand Down Expand Up @@ -306,6 +307,8 @@ impl CStringVec {
}
}



#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -333,3 +336,24 @@ mod tests {
let _c_array = CStringVec::new(&values).expect_err("should fail");
}
}

/// A zero-value parse error, used to initialize types that get passed into FFI code.
pub static NO_PARSE_ERROR: sys::UParseError = sys::UParseError {
line: 0,
offset: 0,
preContext: [0; 16usize],
postContext: [0; 16usize],
};

/// Converts a parse error to a Result.
pub fn parse_ok(e: sys::UParseError) -> Result<(), crate::Error> {
if e == NO_PARSE_ERROR {
return Ok(());
}
Err(Error::Wrapper(anyhow!(
"parse error: line: {}, offset: {}",
e.line,
e.offset
)))
}

Loading

0 comments on commit da87413

Please sign in to comment.