// Read an error from the Lammps API if there is one.
// (This removes the error, so that a second call will produce None.)
Read an error from the Lammps API if there is one.
(This removes the error, so that a second call will produce None.)
Read an error from the Lammps API if there is one . ( This removes the error so that a second call will produce None . )
pub(in crate::low_level) fn pop_error(&mut self) -> Option<(Severity, String)>
    {
        use lammps_sys::{lammps_get_last_error_message, lammps_has_error};
        api_trace!("lammps_has_error({:p})", self.ptr);
        let has_error = unsafe { lammps_has_error(self.ptr) } != 0;
        if !has_error {
            return None;
        };
        // +1 to guarantee a nul
        let mut buf = vec![0u8; MAX_ERROR_BYTES + 1];
        let severity_int = unsafe {
            api_trace!("lammps_get_last_error_message({:p}, (out), {})", self.ptr, MAX_ERROR_BYTES);
            lammps_get_last_error_message(
                self.ptr,
                buf.as_mut_ptr() as *mut c_char,
                MAX_ERROR_BYTES.try_to_c_int().unwrap(),
            )
        } as u32;
        let severity = Severity::from_int(severity_int).expect("lammps-wrap bug!");
        // truncate to written content
        let nul = buf.iter().position(|&c| c == b'\0').expect("lammps-wrap bug!");
        buf.truncate(nul);
        // (NOTE: the thought here was: if our guess for a maximum length
        //        happened to be right in the middle of a character,
        //        then we should cut off the invalid part...
        //        ...but now that I think about it, who says the error
        //        is even encoded in utf8?)
        let message = string_from_utf8_prefix(buf);
        Some((severity, message))
    }
pub ( in crate :: low_level ) fn pop_error ( & mut self ) -> Option < ( Severity , String ) > { use lammps_sys :: { lammps_get_last_error_message , lammps_has_error } ; api_trace ! ( " " self ptr ) ; let has_error = unsafe { lammps_has_error ( self . ptr ) } != 0 ; if ! has_error { return None ; } ; // +1 to guarantee a nul let mut buf = vec ! [ 0u8 MAX_ERROR_BYTES 1 ] ; let severity_int = unsafe { api_trace ! ( " " self ptr MAX_ERROR_BYTES ) ; lammps_get_last_error_message ( self . ptr , buf . as_mut_ptr ( ) as * mut c_char , MAX_ERROR_BYTES . try_to_c_int ( ) . unwrap ( ) , ) } as u32 ; let severity = Severity :: from_int ( severity_int ) . expect ( " " ) ; // truncate to written content let nul = buf . iter ( ) . position ( | & c | c == b'\0' ) . expect ( " " ) ; buf . truncate ( nul ) ; // (NOTE: the thought here was: if our guess for a maximum length //        happened to be right in the middle of a character, //        then we should cut off the invalid part... //        ...but now that I think about it, who says the error //        is even encoded in utf8?) let message = string_from_utf8_prefix ( buf ) ; Some ( ( severity , message ) ) }
Read an error from the Lammps API if there is one.
Read an error from the Lammps API if there is one .
&mut self