mirror of
https://github.com/simonask/libyaml-safer
synced 2024-11-12 22:57:12 +00:00
Expose .fail as the opposite of .ok
This commit is contained in:
parent
c47432e38b
commit
fb6de5f433
3 changed files with 23 additions and 5 deletions
|
@ -47,7 +47,7 @@ pub(crate) unsafe fn unsafe_main(
|
|||
) -> Result<(), Box<dyn Error>> {
|
||||
let mut emitter = MaybeUninit::<yaml_emitter_t>::uninit();
|
||||
let emitter = emitter.as_mut_ptr();
|
||||
if !yaml_emitter_initialize(emitter).ok {
|
||||
if yaml_emitter_initialize(emitter).fail {
|
||||
return Err("Could not initalize the emitter object".into());
|
||||
}
|
||||
|
||||
|
@ -133,10 +133,10 @@ pub(crate) unsafe fn unsafe_main(
|
|||
break Err(format!("Unknown event: '{}'", CStr::from_ptr(line)).into());
|
||||
};
|
||||
|
||||
if !result.ok {
|
||||
if result.fail {
|
||||
break Err("Memory error: Not enough memory for creating an event".into());
|
||||
}
|
||||
if !yaml_emitter_emit(emitter, event).ok {
|
||||
if yaml_emitter_emit(emitter, event).fail {
|
||||
break Err(match (*emitter).error {
|
||||
YAML_MEMORY_ERROR => "Memory error: Not enough memory for emitting".into(),
|
||||
YAML_WRITER_ERROR => {
|
||||
|
|
|
@ -40,7 +40,7 @@ pub(crate) unsafe fn unsafe_main(
|
|||
) -> Result<(), Box<dyn Error>> {
|
||||
let mut parser = MaybeUninit::<yaml_parser_t>::uninit();
|
||||
let parser = parser.as_mut_ptr();
|
||||
if !yaml_parser_initialize(parser).ok {
|
||||
if yaml_parser_initialize(parser).fail {
|
||||
return Err("Could not initialize the parser object".into());
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ pub(crate) unsafe fn unsafe_main(
|
|||
let mut event = MaybeUninit::<yaml_event_t>::uninit();
|
||||
let event = event.as_mut_ptr();
|
||||
loop {
|
||||
if !yaml_parser_parse(parser, event).ok {
|
||||
if yaml_parser_parse(parser, event).fail {
|
||||
let mut error = format!("Parse error: {}", CStr::from_ptr((*parser).problem));
|
||||
if (*parser).problem_mark.line != 0 || (*parser).problem_mark.column != 0 {
|
||||
let _ = write!(
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use core::ops::Deref;
|
||||
|
||||
pub const OK: Success = Success { ok: true };
|
||||
pub const FAIL: Success = Success { ok: false };
|
||||
|
||||
|
@ -6,6 +8,22 @@ pub struct Success {
|
|||
pub ok: bool,
|
||||
}
|
||||
|
||||
pub struct Failure {
|
||||
pub fail: bool,
|
||||
}
|
||||
|
||||
impl Deref for Success {
|
||||
type Target = Failure;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
if self.ok {
|
||||
&Failure { fail: false }
|
||||
} else {
|
||||
&Failure { fail: true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Zero;
|
||||
|
||||
impl PartialEq<Zero> for Success {
|
||||
|
|
Loading…
Reference in a new issue