pub trait PrintInformation
{
#[inline(always)]
fn print_information_to_standard_out(&self)
{
self.print_information_to_stream(unsafe { stdout } as *mut _)
}
#[inline(always)]
fn print_information_to_standard_error(&self)
{
self.print_information_to_stream(unsafe { stderr } as *mut _)
}
#[inline(always)]
fn print_information_to_file(&self, file: File) -> Result<(), io::Error>
{
let file_descriptor = file.into_raw_fd();
const open_flags: ConstCStr = ConstCStr(b"a\0");
let stream = unsafe { fdopen(file_descriptor, open_flags.as_ptr()) };
if stream.is_null()
{
return Err(io::Error::last_os_error());
}
self.print_information_to_stream(stream);
match unsafe { fflush(stream) }
{
0 => (),
EOF =>
{
unsafe { fclose(stream) };
return Err(io::Error::last_os_error())
}
unexpected @ _ =>
{
unsafe { fclose(stream) };
panic!("Unexpected result code '{}' from 'fflush'", unexpected)
}
}
match unsafe { fclose(stream) }
{
0 => Ok(()),
EOF => Err(io::Error::last_os_error()),
unexpected @ _ => panic!("Unexpected result code '{}' from 'fclose'", unexpected),
}
}
#[inline(always)]
fn print_information_to_c_string(&self) -> Result<CString, io::Error>
{
let mut buffer = unsafe { uninitialized() };
let mut size = unsafe { uninitialized() };
let stream = unsafe { open_memstream(&mut buffer, &mut size) };
if stream.is_null()
{
return Err(io::Error::last_os_error());
}
self.print_information_to_stream(stream);
match unsafe { fflush(stream) }
{
0 => (),
EOF =>
{
unsafe { fclose(stream) };
unsafe { free(buffer as *mut c_void) };
return Err(io::Error::last_os_error())
}
unexpected @ _ =>
{
unsafe { fclose(stream) };
unsafe { free(buffer as *mut c_void) };
panic!("Unexpected result code '{}' from 'fflush'", unexpected)
}
}
match unsafe { fclose(stream) }
{
0 => (),
EOF =>
{
unsafe { free(buffer as *mut c_void) };
return Err(io::Error::last_os_error())
}
unexpected @ _ =>
{
unsafe { free(buffer as *mut c_void) };
panic!("Unexpected result code '{}' from 'fclose'", unexpected)
}
}
let c_string = unsafe { CStr::from_ptr(buffer) }.into();
unsafe { free(buffer as *mut c_void) };
Ok(c_string)
}
#[doc(hidden)]
#[inline(always)]
fn print_information_to_stream(&self, stream: *mut FILE);
}