Expose readonly access to error messages

This commit is contained in:
David Tolnay 2022-07-08 15:44:09 -07:00
parent f55f31b57a
commit 824b0966a8
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -1,4 +1,6 @@
use crate::libc;
use core::ops::Deref;
use core::ptr::addr_of;
pub use self::{
yaml_break_t::*, yaml_emitter_state_t::*, yaml_encoding_t::*, yaml_error_type_t::*,
@ -712,22 +714,39 @@ pub struct yaml_alias_data_t {
#[non_exhaustive]
pub struct yaml_parser_t {
/// Error type.
#[doc(hidden)]
#[cfg(doc)]
pub error: yaml_error_type_t,
#[cfg(not(doc))]
pub(crate) error: yaml_error_type_t,
/// Error description.
#[doc(hidden)]
#[cfg(doc)]
pub problem: *const libc::c_char,
#[cfg(not(doc))]
pub(crate) problem: *const libc::c_char,
/// The byte about which the problem occured.
#[doc(hidden)]
#[cfg(doc)]
pub problem_offset: size_t,
#[cfg(not(doc))]
pub(crate) problem_offset: size_t,
/// The problematic value (-1 is none).
#[cfg(doc)]
pub problem_value: libc::c_int,
#[cfg(not(doc))]
pub(crate) problem_value: libc::c_int,
/// The problem position.
#[doc(hidden)]
#[cfg(doc)]
pub problem_mark: yaml_mark_t,
#[cfg(not(doc))]
pub(crate) problem_mark: yaml_mark_t,
/// The error context.
#[cfg(doc)]
pub context: *const libc::c_char,
#[cfg(not(doc))]
pub(crate) context: *const libc::c_char,
/// The context position.
#[cfg(doc)]
pub context_mark: yaml_mark_t,
#[cfg(not(doc))]
pub(crate) context_mark: yaml_mark_t,
/// Read handler.
pub(crate) read_handler: Option<yaml_read_handler_t>,
@ -783,6 +802,33 @@ pub struct yaml_parser_t {
pub(crate) document: *mut yaml_document_t,
}
#[repr(C)]
#[non_exhaustive]
pub struct yaml_parser_t_prefix {
/// Error type.
pub error: yaml_error_type_t,
/// Error description.
pub problem: *const libc::c_char,
/// The byte about which the problem occured.
pub problem_offset: size_t,
/// The problematic value (-1 is none).
pub problem_value: libc::c_int,
/// The problem position.
pub problem_mark: yaml_mark_t,
/// The error context.
pub context: *const libc::c_char,
/// The context position.
pub context_mark: yaml_mark_t,
}
#[doc(hidden)]
impl Deref for yaml_parser_t {
type Target = yaml_parser_t_prefix;
fn deref(&self) -> &Self::Target {
unsafe { &*addr_of!(*self).cast() }
}
}
#[derive(Copy, Clone)]
#[repr(C)]
pub(crate) union unnamed_yaml_parser_t_input {
@ -991,11 +1037,15 @@ pub(crate) struct yaml_anchors_t {
#[non_exhaustive]
pub struct yaml_emitter_t {
/// Error type.
#[doc(hidden)]
#[cfg(doc)]
pub error: yaml_error_type_t,
#[cfg(not(doc))]
pub(crate) error: yaml_error_type_t,
/// Error description.
#[doc(hidden)]
#[cfg(doc)]
pub problem: *const libc::c_char,
#[cfg(not(doc))]
pub(crate) problem: *const libc::c_char,
/// Write handler.
pub(crate) write_handler: Option<yaml_write_handler_t>,
/// A pointer for passing to the write handler.
@ -1068,6 +1118,23 @@ pub struct yaml_emitter_t {
pub(crate) document: *mut yaml_document_t,
}
#[repr(C)]
#[non_exhaustive]
pub struct yaml_emitter_t_prefix {
/// Error type.
pub error: yaml_error_type_t,
/// Error description.
pub problem: *const libc::c_char,
}
#[doc(hidden)]
impl Deref for yaml_emitter_t {
type Target = yaml_emitter_t_prefix;
fn deref(&self) -> &Self::Target {
unsafe { &*addr_of!(*self).cast() }
}
}
#[derive(Copy, Clone)]
#[repr(C)]
pub(crate) union unnamed_yaml_emitter_t_output {