mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-18 03:25:55 +00:00
[rust] fix hundreds of clippy warnings
This commit is contained in:
parent
129e208438
commit
b7bfbb0f90
@ -12,6 +12,7 @@ use crate::NcChannel;
|
||||
impl NcCell {
|
||||
/// New NcCell, expects a 7-bit [char].
|
||||
#[inline]
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
pub const fn with_char7b(ch: char) -> Self {
|
||||
NcCell {
|
||||
gcluster: (ch as u32).to_le(),
|
||||
|
@ -192,6 +192,7 @@ pub fn nccell_bg_palindex_p(cell: &NcCell) -> bool {
|
||||
///
|
||||
/// *Method: NcCell.[fg_palindex()][NcCell#method.fg_palindex].*
|
||||
#[inline]
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
pub const fn nccell_fg_palindex(cell: &NcCell) -> NcPaletteIndex {
|
||||
((cell.channels & 0xff00000000 as NcChannelPair) >> 32) as NcPaletteIndex
|
||||
}
|
||||
@ -200,6 +201,7 @@ pub const fn nccell_fg_palindex(cell: &NcCell) -> NcPaletteIndex {
|
||||
///
|
||||
/// *Method: NcCell.[bg_palindex()][NcCell#method.bg_palindex].*
|
||||
#[inline]
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
pub const fn nccell_bg_palindex(cell: &NcCell) -> NcPaletteIndex {
|
||||
(cell.channels & 0xff) as NcPaletteIndex
|
||||
}
|
||||
@ -213,6 +215,7 @@ pub const fn nccell_bg_palindex(cell: &NcCell) -> NcPaletteIndex {
|
||||
//
|
||||
// NOTE: unlike the original C function, this one can't fail
|
||||
#[inline]
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
pub fn nccell_set_fg_palindex(cell: &mut NcCell, index: NcPaletteIndex) {
|
||||
cell.channels |= NCCELL_FGDEFAULT_MASK;
|
||||
cell.channels |= NCCELL_FG_PALETTE;
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Test `NcCell` methods and associated functions.
|
||||
|
||||
use crate::{Notcurses, NcCell, NcPlane};
|
||||
use crate::{NcCell, NcPlane, Notcurses};
|
||||
|
||||
use serial_test::serial;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
//! `NcChannel*` methods and associated functions.
|
||||
#![allow(clippy::unnecessary_cast)]
|
||||
|
||||
use crate::{NcAlphaBits, NcChannel, NcChannelPair, NcColor, NcPaletteIndex, NcRgb};
|
||||
|
||||
|
@ -487,6 +487,7 @@ pub fn ncchannels_bg_palindex_p(channels: NcChannelPair) -> bool {
|
||||
///
|
||||
/// *Method: NcChannelPair.[set_fg_palindex()][NcChannelPair#method.set_fg_palindex]*
|
||||
#[inline]
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
pub fn ncchannels_set_fg_palindex(channels: &mut NcChannelPair, index: NcPaletteIndex) {
|
||||
*channels |= NCCELL_FGDEFAULT_MASK;
|
||||
*channels |= NCCELL_FG_PALETTE as NcChannelPair;
|
||||
|
@ -84,7 +84,6 @@ fn channel_set() {
|
||||
assert_eq!(false, crate::ncchannel_default_p(c));
|
||||
}
|
||||
|
||||
|
||||
/// gets the alpha component
|
||||
#[test]
|
||||
#[serial]
|
||||
@ -128,11 +127,14 @@ fn channel_set_default() {
|
||||
assert_eq!(0x_20_112233, channel_transp); // the transparent bit is now set
|
||||
|
||||
crate::ncchannel_set_not_default(&mut channel_transp);
|
||||
// both the "not default" & transparent bits are now set
|
||||
// both the "not default" & transparent bits are now set
|
||||
assert_eq!(0x_60_112233, channel_transp);
|
||||
|
||||
// and calling set_default() should make it both default & opaque again
|
||||
assert_eq!(0x_00_112233, crate::ncchannel_set_default(&mut channel_transp));
|
||||
assert_eq!(
|
||||
0x_00_112233,
|
||||
crate::ncchannel_set_default(&mut channel_transp)
|
||||
);
|
||||
}
|
||||
|
||||
/// sets the channel as *not* using the default color
|
||||
|
@ -297,14 +297,13 @@ impl NcDirect {
|
||||
/// Must not be called concurrently with either input or rasterization.
|
||||
///
|
||||
/// *C style function: [ncdirect_check_pixel_support()][crate::ncdirect_check-pixel_support].*
|
||||
#[allow(clippy::wildcard_in_or_patterns)]
|
||||
pub fn check_pixel_support(&mut self) -> NcResult<bool> {
|
||||
let res = unsafe { crate::ncdirect_check_pixel_support(self) };
|
||||
match res {
|
||||
0 => return Ok(false),
|
||||
1 => return Ok(true),
|
||||
NCRESULT_ERR | _ => {
|
||||
return Err(NcError::with_msg(res, "NcDirect.check_pixel_support()"));
|
||||
}
|
||||
0 => Ok(false),
|
||||
1 => Ok(true),
|
||||
NCRESULT_ERR | _ => Err(NcError::with_msg(res, "NcDirect.check_pixel_support()")),
|
||||
}
|
||||
}
|
||||
|
||||
@ -552,7 +551,7 @@ impl NcDirect {
|
||||
/// *C style function: [ncdirect_readline()][crate::ncdirect_readline].*
|
||||
pub fn readline(&mut self, prompt: &str) -> NcResult<&str> {
|
||||
let res = unsafe { crate::ncdirect_readline(self, cstring![prompt]) };
|
||||
if res != null_mut() {
|
||||
if !res.is_null() {
|
||||
return Ok(rstring![res]);
|
||||
} else {
|
||||
Err(NcError::with_msg(
|
||||
|
@ -32,7 +32,7 @@ impl NcFadeCtx {
|
||||
/// Rather than the simple ncplane_fade{in/out}(),
|
||||
/// ncfadectx_setup() can be paired with a loop over
|
||||
/// ncplane_fade{in/out}_iteration() + ncfadectx_free().
|
||||
pub fn setup<'a>(plane: &'a mut NcPlane) -> &'a mut NcFadeCtx {
|
||||
pub fn setup(plane: &mut NcPlane) -> &mut NcFadeCtx {
|
||||
unsafe { &mut *crate::ncfadectx_setup(plane) }
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,17 @@ use core::ptr::{null_mut, NonNull};
|
||||
|
||||
use std::io::{Error, ErrorKind, Read, Seek, SeekFrom};
|
||||
|
||||
use libc::{c_long, c_void, fclose, feof, fread, fseek, ftell, SEEK_CUR, SEEK_END, SEEK_SET};
|
||||
use libc::{
|
||||
c_long, c_void, fclose, /* feof, */ fread, fseek, ftell, SEEK_CUR, SEEK_END, SEEK_SET,
|
||||
};
|
||||
|
||||
/// See [NcFile]. Notcurses functions expects this type of `*FILE` (a struct)
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
pub type FILE_NC = crate::ffi::_IO_FILE;
|
||||
|
||||
/// See [NcFile]. The [`libc`](https://docs.rs/libc/) crate expects this type
|
||||
/// of `*FILE` (an opaque enum)
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
pub type FILE_LIBC = libc::FILE;
|
||||
|
||||
// TODO: the following static strings aren't made public
|
||||
@ -22,34 +26,34 @@ pub type FILE_LIBC = libc::FILE;
|
||||
/// It will open the file in a way that will allow reading and writing,
|
||||
/// including overwriting old data.
|
||||
/// It will not create the file if it does not exist.
|
||||
pub static RANDOM_ACCESS_MODE: &'static str = "rb+";
|
||||
pub static RANDOM_ACCESS_MODE: &str = "rb+";
|
||||
|
||||
/// Intended to be passed into the CFile::open method.
|
||||
/// It will open the file in a way that will allow reading and writing,
|
||||
/// including overwriting old data
|
||||
pub static UPDATE: &'static str = "rb+";
|
||||
pub static UPDATE: &str = "rb+";
|
||||
|
||||
/// Intended to be passed into the CFile::open method.
|
||||
/// It will only allow reading.
|
||||
pub static READ_ONLY: &'static str = "r";
|
||||
pub static READ_ONLY: &str = "r";
|
||||
|
||||
/// Intended to be passed into the CFile::open method.
|
||||
/// It will only allow writing.
|
||||
pub static WRITE_ONLY: &'static str = "w";
|
||||
pub static WRITE_ONLY: &str = "w";
|
||||
|
||||
/// Intended to be passed into the CFile::open method.
|
||||
/// It will only allow data to be appended to the end of the file.
|
||||
pub static APPEND_ONLY: &'static str = "a";
|
||||
pub static APPEND_ONLY: &str = "a";
|
||||
|
||||
/// Intended to be passed into the CFile::open method.
|
||||
/// It will allow data to be appended to the end of the file, and data to be
|
||||
/// read from the file. It will create the file if it doesn't exist.
|
||||
pub static APPEND_READ: &'static str = "a+";
|
||||
pub static APPEND_READ: &str = "a+";
|
||||
|
||||
/// Intended to be passed into the CFile::open method.
|
||||
/// It will open the file in a way that will allow reading and writing,
|
||||
/// including overwriting old data. It will create the file if it doesn't exist
|
||||
pub static TRUNCATE_RANDOM_ACCESS_MODE: &'static str = "wb+";
|
||||
pub static TRUNCATE_RANDOM_ACCESS_MODE: &str = "wb+";
|
||||
|
||||
/// A utility function to pull the current value of errno and put it into an
|
||||
/// Error::Errno
|
||||
@ -83,9 +87,9 @@ impl NcFile {
|
||||
}
|
||||
|
||||
/// `NcFile` constructor from a file produced by the libc crate
|
||||
pub fn from_libc(file: *mut FILE_LIBC) -> Self {
|
||||
pub unsafe fn from_libc(file: *mut FILE_LIBC) -> Self {
|
||||
NcFile {
|
||||
file_ptr: unsafe { NonNull::new_unchecked(file) },
|
||||
file_ptr: NonNull::new_unchecked(file),
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,11 +269,13 @@ impl Read for NcFile {
|
||||
Ok(())
|
||||
} else {
|
||||
// Check if we hit the end of the file
|
||||
if feof(self.as_libc_ptr()) != 0 {
|
||||
get_error()
|
||||
} else {
|
||||
get_error()
|
||||
}
|
||||
// FIXME
|
||||
// if feof(self.as_libc_ptr()) != 0 {
|
||||
// get_error()
|
||||
// } else {
|
||||
// get_error()
|
||||
// }
|
||||
get_error()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
//! Special composed key definitions. These values are added to 0x100000.
|
||||
#![allow(clippy::transmute_int_to_char)]
|
||||
|
||||
use std::mem::transmute;
|
||||
|
||||
|
@ -90,7 +90,7 @@
|
||||
//! };
|
||||
//! unsafe {
|
||||
//! let nc = notcurses_init(&options, null_mut());
|
||||
//! if nc == null_mut() {
|
||||
//! if nc.is_null() {
|
||||
//! exit(1);
|
||||
//! }
|
||||
//! let plane = notcurses_stdplane(nc);
|
||||
@ -117,7 +117,7 @@
|
||||
//! - [Doxygen Documentation](https://nick-black.com/notcurses/html/index.html)
|
||||
//!
|
||||
#![allow(non_upper_case_globals, non_camel_case_types, non_snake_case)]
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
#![allow(clippy::too_many_arguments, clippy::needless_doctest_main)]
|
||||
|
||||
mod bindings;
|
||||
#[doc(inline)]
|
||||
|
@ -140,7 +140,7 @@ macro_rules! error {
|
||||
/// or an `Err(`[`NcError`]`)` if the pointer is null.
|
||||
///
|
||||
/// In other words:
|
||||
/// Returns Ok(&*`$ptr`) if `$ptr` != `null()`, otherwise returns
|
||||
/// Returns Ok(&*`$ptr`) if `!$ptr.is_null()`, otherwise returns
|
||||
/// Err([NcError]]::[new][NcError#method.new]([NCRESULT_ERR], `$msg`)).
|
||||
///
|
||||
/// `$msg` is optional. By default it will be an empty `&str` `""`.
|
||||
@ -169,7 +169,7 @@ macro_rules! error_ref {
|
||||
/// or an `Err(`[`NcError`]`)` if the pointer is null.
|
||||
///
|
||||
/// In other words:
|
||||
/// Returns Ok(&mut *`$ptr`) if `$ptr` != `null_mut()`, otherwise returns
|
||||
/// Returns Ok(&mut *`$ptr`) if `!$ptr._is_null()`, otherwise returns
|
||||
/// Err([NcError]]::[new][NcError#method.new]([NCRESULT_ERR], `$msg`)).
|
||||
///
|
||||
/// `$msg` is optional. By default it will be an empty `&str` `""`.
|
||||
@ -198,14 +198,14 @@ macro_rules! error_ref_mut {
|
||||
/// or an `Err(`[`NcError`]`)` if the pointer is null.
|
||||
///
|
||||
/// In other words:
|
||||
/// Returns Ok((&*`$str`).to_string()) if `$str` != `null()`, otherwise returns
|
||||
/// Returns Ok((&*`$str`).to_string()) if `!$str.is_null()`, otherwise returns
|
||||
/// Err([NcError]]::[new][NcError#method.new]([NCRESULT_ERR], `$msg`)).
|
||||
///
|
||||
/// `$msg` is optional. By default it will be an empty `&str` `""`.
|
||||
#[macro_export]
|
||||
macro_rules! error_str {
|
||||
($str:expr, $msg:expr) => {
|
||||
if $str != core::ptr::null_mut() {
|
||||
if $str.is_null() {
|
||||
#[allow(unused_unsafe)]
|
||||
return Ok(unsafe { (&*$str).to_string() });
|
||||
} else {
|
||||
|
@ -156,7 +156,7 @@ impl Notcurses {
|
||||
/// Returns the bottommost [NcPlane], of which there is always at least one.
|
||||
///
|
||||
/// *C style function: [notcurses_bottom()][crate::notcurses_bottom].*
|
||||
pub fn bottom<'a>(&'a mut self) -> &'a mut NcPlane {
|
||||
pub fn bottom(&mut self) -> &mut NcPlane {
|
||||
unsafe { &mut *crate::notcurses_bottom(self) }
|
||||
}
|
||||
|
||||
@ -259,14 +259,13 @@ impl Notcurses {
|
||||
/// Must not be called concurrently with either input or rasterization.
|
||||
///
|
||||
/// *C style function: [notcurses_check_pixel_support()][crate::notcurses_check-pixel_support].*
|
||||
#[allow(clippy::wildcard_in_or_patterns)]
|
||||
pub fn check_pixel_support(&mut self) -> NcResult<bool> {
|
||||
let res = unsafe { crate::notcurses_check_pixel_support(self) };
|
||||
match res {
|
||||
0 => return Ok(false),
|
||||
1 => return Ok(true),
|
||||
NCRESULT_ERR | _ => {
|
||||
return Err(NcError::with_msg(res, "Notcuses.check_pixel_support()"));
|
||||
}
|
||||
0 => Ok(false),
|
||||
1 => Ok(true),
|
||||
NCRESULT_ERR | _ => Err(NcError::with_msg(res, "Notcuses.check_pixel_support()")),
|
||||
}
|
||||
}
|
||||
|
||||
@ -396,7 +395,7 @@ impl Notcurses {
|
||||
|
||||
// An invalid read is indicated with -1
|
||||
if res as u32 as i32 != -1 {
|
||||
return Ok(res);
|
||||
Ok(res)
|
||||
} else {
|
||||
error![
|
||||
-1,
|
||||
@ -586,7 +585,7 @@ impl Notcurses {
|
||||
/// Notcurses might enlarge this structure.
|
||||
///
|
||||
/// *C style function: [notcurses_stats_alloc()][crate::notcurses_stats_alloc].*
|
||||
pub fn stats_alloc<'a>(&'a mut self) -> &'a mut NcStats {
|
||||
pub fn stats_alloc(&mut self) -> &mut NcStats {
|
||||
unsafe { &mut *crate::notcurses_stats_alloc(self) }
|
||||
}
|
||||
|
||||
@ -690,7 +689,7 @@ impl Notcurses {
|
||||
/// Returns the topmost [NcPlane], of which there is always at least one.
|
||||
///
|
||||
/// *C style function: [notcurses_top()][crate::notcurses_top].*
|
||||
pub fn top<'a>(&'a mut self) -> &'a mut NcPlane {
|
||||
pub fn top(&mut self) -> &mut NcPlane {
|
||||
unsafe { &mut *crate::notcurses_top(self) }
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ pub fn notcurses_getc_nblock(nc: &mut Notcurses, input: &mut NcInput) -> char {
|
||||
tv_sec: 0,
|
||||
tv_nsec: 0,
|
||||
};
|
||||
core::char::from_u32_unchecked(crate::notcurses_getc(nc, &ts, &mut sigmask, input))
|
||||
core::char::from_u32_unchecked(crate::notcurses_getc(nc, &ts, &sigmask, input))
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ pub fn notcurses_getc_blocking(nc: &mut Notcurses, input: Option<&mut NcInput>)
|
||||
unsafe {
|
||||
let mut sigmask = NcSignalSet::new();
|
||||
sigmask.emptyset();
|
||||
core::char::from_u32_unchecked(crate::notcurses_getc(nc, null(), &mut sigmask, input_ptr))
|
||||
core::char::from_u32_unchecked(crate::notcurses_getc(nc, null(), &sigmask, input_ptr))
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ pub fn notcurses_stddim_yx<'a>(
|
||||
) -> NcResult<&'a mut NcPlane> {
|
||||
unsafe {
|
||||
let sp = crate::notcurses_stdplane(nc);
|
||||
if sp != null_mut() {
|
||||
if !sp.is_null() {
|
||||
crate::ncplane_dim_yx(sp, &mut (*y as i32), &mut (*x as i32));
|
||||
return Ok(&mut *sp);
|
||||
}
|
||||
@ -104,7 +104,7 @@ pub fn notcurses_stddim_yx_const<'a>(
|
||||
) -> NcResult<&'a NcPlane> {
|
||||
unsafe {
|
||||
let sp = crate::notcurses_stdplane_const(nc);
|
||||
if sp != null() {
|
||||
if !sp.is_null() {
|
||||
crate::ncplane_dim_yx(sp, &mut (*y as i32), &mut (*x as i32));
|
||||
return Ok(&*sp);
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ pub type NcPixel = u32;
|
||||
|
||||
/// Constructs a libav-compatible ABGR pixel from [NcColor] RGB components.
|
||||
#[inline]
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
pub const fn ncpixel(red: NcColor, green: NcColor, blue: NcColor) -> NcPixel {
|
||||
0xff000000 as NcPixel | red as NcPixel | (blue as NcPixel) << 8 | (green as NcPixel) << 16
|
||||
}
|
||||
|
@ -285,12 +285,7 @@ impl NcPlane {
|
||||
#[inline]
|
||||
pub fn fg_rgb8(&self) -> (NcColor, NcColor, NcColor) {
|
||||
let (mut r, mut g, mut b) = (0, 0, 0);
|
||||
let _ = crate::ncchannels_fg_rgb8(
|
||||
crate::ncplane_channels(self),
|
||||
&mut r,
|
||||
&mut g,
|
||||
&mut b,
|
||||
);
|
||||
let _ = crate::ncchannels_fg_rgb8(crate::ncplane_channels(self), &mut r, &mut g, &mut b);
|
||||
(r, g, b)
|
||||
}
|
||||
|
||||
@ -300,12 +295,7 @@ impl NcPlane {
|
||||
#[inline]
|
||||
pub fn bg_rgb8(&self) -> (NcColor, NcColor, NcColor) {
|
||||
let (mut r, mut g, mut b) = (0, 0, 0);
|
||||
let _ = crate::ncchannels_bg_rgb8(
|
||||
crate::ncplane_channels(self),
|
||||
&mut r,
|
||||
&mut g,
|
||||
&mut b,
|
||||
);
|
||||
let _ = crate::ncchannels_bg_rgb8(crate::ncplane_channels(self), &mut r, &mut g, &mut b);
|
||||
(r, g, b)
|
||||
}
|
||||
|
||||
@ -831,7 +821,7 @@ impl NcPlane {
|
||||
let cols = self.putstr(string)?;
|
||||
let (y, _x) = self.cursor_yx();
|
||||
self.cursor_move_yx(y + 1, 0)?;
|
||||
return Ok(cols);
|
||||
Ok(cols)
|
||||
}
|
||||
|
||||
/// Same as [putstr_yx()][NcPlane#method.putstr_yx] but [NcAlign]ed on x.
|
||||
@ -929,14 +919,14 @@ impl NcPlane {
|
||||
/// *C style function: [ncplane_dup()][crate::ncplane_dup].*
|
||||
//
|
||||
// TODO: deal with the opaque field.
|
||||
pub fn dup<'a>(&'a mut self) -> &'a mut NcPlane {
|
||||
pub fn dup(&mut self) -> &mut NcPlane {
|
||||
unsafe { &mut *crate::ncplane_dup(self, null_mut()) }
|
||||
}
|
||||
|
||||
/// Returns the topmost NcPlane of the current pile.
|
||||
///
|
||||
/// *C style function: [ncpile_top()][crate::ncpile_top].*
|
||||
pub fn top<'a>(&mut self) -> &'a mut NcPlane {
|
||||
pub fn top(&mut self) -> &mut NcPlane {
|
||||
unsafe { &mut *crate::ncpile_top(self) }
|
||||
}
|
||||
|
||||
@ -994,14 +984,14 @@ impl NcPlane {
|
||||
/// Returns the NcPlane above this one, or None if already at the top.
|
||||
///
|
||||
/// *C style function: [ncplane_above()][crate::ncplane_above].*
|
||||
pub fn above<'a>(&'a mut self) -> NcResult<&'a mut NcPlane> {
|
||||
pub fn above(&mut self) -> NcResult<&mut NcPlane> {
|
||||
error_ref_mut![unsafe { crate::ncplane_above(self) }, "NcPlane.above()"]
|
||||
}
|
||||
|
||||
/// Returns the NcPlane below this one, or None if already at the bottom.
|
||||
///
|
||||
/// *C style function: [ncplane_below()][crate::ncplane_below].*
|
||||
pub fn below<'a>(&'a mut self) -> NcResult<&'a mut NcPlane> {
|
||||
pub fn below(&mut self) -> NcResult<&mut NcPlane> {
|
||||
error_ref_mut![unsafe { crate::ncplane_below(self) }, "NcPlane.below()"]
|
||||
}
|
||||
|
||||
@ -1098,7 +1088,7 @@ impl NcPlane {
|
||||
/// *C style function: [ncplane_parent()][crate::ncplane_parent].*
|
||||
//
|
||||
// TODO: CHECK: what happens when it's bound to itself.
|
||||
pub fn parent<'a>(&'a mut self) -> NcResult<&'a mut NcPlane> {
|
||||
pub fn parent(&mut self) -> NcResult<&mut NcPlane> {
|
||||
error_ref_mut![unsafe { crate::ncplane_parent(self) }, "NcPlane.parent()"]
|
||||
}
|
||||
|
||||
@ -1107,7 +1097,7 @@ impl NcPlane {
|
||||
/// *C style function: [ncplane_parent_const()][crate::ncplane_parent_const].*
|
||||
//
|
||||
// CHECK: what happens when it's bound to itself.
|
||||
pub fn parent_const<'a>(&'a self) -> NcResult<&'a NcPlane> {
|
||||
pub fn parent_const(&self) -> NcResult<&NcPlane> {
|
||||
error_ref![
|
||||
unsafe { crate::ncplane_parent_const(self) },
|
||||
"NcPlane.parent_const()"
|
||||
@ -1155,7 +1145,7 @@ impl NcPlane {
|
||||
/// rendered (doing so will likely result in a blank screen).
|
||||
///
|
||||
/// *C style function: [ncpile_rasterize()][crate::ncpile_rasterize].*
|
||||
pub fn rasterize<'a>(&mut self) -> NcResult<()> {
|
||||
pub fn rasterize(&mut self) -> NcResult<()> {
|
||||
error![
|
||||
unsafe { crate::ncpile_rasterize(self) },
|
||||
"NcPlane.rasterize()"
|
||||
@ -1167,7 +1157,7 @@ impl NcPlane {
|
||||
/// To actually write out the render, call ncpile_rasterize().
|
||||
///
|
||||
/// *C style function: [ncpile_render()][crate::ncpile_render].*
|
||||
pub fn render<'a>(&mut self) -> NcResult<()> {
|
||||
pub fn render(&mut self) -> NcResult<()> {
|
||||
error![unsafe { crate::ncpile_render(self) }, "NcPlane.render()"]
|
||||
}
|
||||
|
||||
@ -1943,7 +1933,6 @@ impl NcPlane {
|
||||
y_stop: NcDim,
|
||||
x_stop: NcDim,
|
||||
) -> NcResult<NcDim> {
|
||||
|
||||
// https://github.com/dankamongmen/notcurses/issues/1339
|
||||
#[cfg(any(target_arch = "x86_64", target_arch = "i686"))]
|
||||
let egc_ptr = &(*egc as i8);
|
||||
|
@ -4,9 +4,8 @@ use core::ptr::null_mut;
|
||||
|
||||
use crate::ffi::__va_list_tag;
|
||||
use crate::{
|
||||
cstring, nccell_release, NcAlign, NcAlphaBits, NcBoxMask, NcCell, NcChannel,
|
||||
NcChannelPair, NcColor, NcDim, NcEgc, NcIntResult, NcPlane, NcRgb, NcStyleMask, NCRESULT_ERR,
|
||||
NCRESULT_OK,
|
||||
cstring, nccell_release, NcAlign, NcAlphaBits, NcBoxMask, NcCell, NcChannel, NcChannelPair,
|
||||
NcColor, NcDim, NcEgc, NcIntResult, NcPlane, NcRgb, NcStyleMask, NCRESULT_ERR, NCRESULT_OK,
|
||||
};
|
||||
|
||||
// Alpha -----------------------------------------------------------------------
|
||||
@ -79,7 +78,6 @@ pub fn ncplane_set_channels(plane: &mut NcPlane, channels: NcChannelPair) {
|
||||
unsafe { crate::ffi::ncplane_set_channels(plane, channels) };
|
||||
}
|
||||
|
||||
|
||||
// NcColor ---------------------------------------------------------------------
|
||||
|
||||
/// Gets the foreground [NcColor] RGB components from an [NcPlane].
|
||||
|
@ -14,7 +14,7 @@ pub type NcResizeCbUnsafe = unsafe extern "C" fn(*mut NcPlane) -> NcIntResult;
|
||||
/// Converts [NcResizeCbUnsafe] to [NcResizeCb].
|
||||
pub fn ncresizecb_to_rust(resizecb: Option<NcResizeCbUnsafe>) -> Option<NcResizeCb> {
|
||||
if let Some(cb) = resizecb {
|
||||
return Some(unsafe { core::mem::transmute(cb) });
|
||||
Some(unsafe { core::mem::transmute(cb) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -26,7 +26,7 @@ pub fn ncresizecb_to_rust(resizecb: Option<NcResizeCbUnsafe>) -> Option<NcResize
|
||||
// to make this function const, and then NcPlaneOptions constructors.
|
||||
pub fn ncresizecb_to_c(resizecb: Option<NcResizeCb>) -> Option<NcResizeCbUnsafe> {
|
||||
if let Some(cb) = resizecb {
|
||||
return Some(unsafe { core::mem::transmute(cb) });
|
||||
Some(unsafe { core::mem::transmute(cb) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ pub type NcStats = crate::bindings::ffi::ncstats;
|
||||
/// # `NcStats` Methods.
|
||||
impl NcStats {
|
||||
/// Allocates an NcStats object.
|
||||
pub fn new<'a>(nc: &'a Notcurses) -> &'a mut Self {
|
||||
pub fn new(nc: &mut Notcurses) -> &mut Self {
|
||||
unsafe { &mut *crate::notcurses_stats_alloc(nc) }
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ impl NcVisual {
|
||||
cols as i32,
|
||||
)
|
||||
},
|
||||
&format!("NcVisual::from_bgra()")
|
||||
"NcVisual::from_bgra()"
|
||||
]
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ impl NcVisual {
|
||||
pub fn from_file<'a>(file: &str) -> NcResult<&'a mut NcVisual> {
|
||||
error_ref_mut![
|
||||
unsafe { crate::ncvisual_from_file(cstring![file]) },
|
||||
&format!("NcVisual::from_file()")
|
||||
&format!("NcVisual::from_file({})", file)
|
||||
]
|
||||
}
|
||||
|
||||
@ -162,7 +162,10 @@ impl NcVisual {
|
||||
len_x as i32,
|
||||
)
|
||||
},
|
||||
&format!("NcVisual::from_file()")
|
||||
&format!(
|
||||
"NcVisual::from_file({}, {}, {}, {}, {})",
|
||||
blitter, beg_y, beg_x, len_y, len_x
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
@ -192,7 +195,7 @@ impl NcVisual {
|
||||
cols as i32,
|
||||
)
|
||||
},
|
||||
&format!("NcVisual::from_rgba()")
|
||||
&format!("NcVisual::from_rgba({}, {}, {})", rows, rowstride, cols)
|
||||
]
|
||||
}
|
||||
|
||||
@ -226,7 +229,7 @@ impl NcVisual {
|
||||
pub fn decode(&mut self) -> NcResult<NcIntResult> {
|
||||
let res = unsafe { crate::ncvisual_decode(self) };
|
||||
if res == NCRESULT_ERR {
|
||||
return Err(NcError::with_msg(res, "NcVisual.decode()"));
|
||||
Err(NcError::with_msg(res, "NcVisual.decode()"))
|
||||
} else {
|
||||
Ok(res)
|
||||
}
|
||||
@ -244,7 +247,7 @@ impl NcVisual {
|
||||
pub fn decode_loop(&mut self) -> NcResult<NcIntResult> {
|
||||
let res = unsafe { crate::ncvisual_decode_loop(self) };
|
||||
if res == NCRESULT_ERR {
|
||||
return Err(NcError::with_msg(res, "NcVisual.decode_loop()"));
|
||||
Err(NcError::with_msg(res, "NcVisual.decode_loop()"))
|
||||
} else {
|
||||
Ok(res)
|
||||
}
|
||||
@ -449,8 +452,8 @@ impl NcVisual {
|
||||
/// *C style function: [ncvisual_subtitle()][crate::ncvisual_subtitle].*
|
||||
pub fn subtitle(&self) -> NcResult<&str> {
|
||||
let res = unsafe { crate::ncvisual_subtitle(self) };
|
||||
if res != null_mut() {
|
||||
return Ok(rstring![res]);
|
||||
if !res.is_null() {
|
||||
Ok(rstring![res])
|
||||
} else {
|
||||
Err(NcError::with_msg(NCRESULT_ERR, "NcVisual.subtitle()"))
|
||||
}
|
||||
|
@ -157,10 +157,11 @@ impl NcMenu {
|
||||
ninput = null_mut();
|
||||
}
|
||||
let res = unsafe { crate::ncmenu_selected(self, ninput) };
|
||||
if res != null_mut() {
|
||||
return Some(unsafe { (&*res).to_string() });
|
||||
if !res.is_null() {
|
||||
Some(unsafe { (&*res).to_string() })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Unrolls the specified [NcMenuSection][crate::NcMenuSection],
|
||||
|
@ -18,7 +18,7 @@ impl NcMenuOptions {
|
||||
style_sections: NcChannelPair,
|
||||
flags: u64,
|
||||
) -> Self {
|
||||
assert![sections.len() > 0];
|
||||
assert![!sections.is_empty()];
|
||||
Self {
|
||||
// array of 'sectioncount' `MenuSection`s
|
||||
sections: sections.as_mut_ptr(),
|
||||
@ -33,7 +33,7 @@ impl NcMenuOptions {
|
||||
sectionchannels: style_sections,
|
||||
|
||||
// flag word of NCMENU_OPTION_*
|
||||
flags: flags,
|
||||
flags,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,7 +50,7 @@ impl NcMenuOptions {
|
||||
/// Returns a mutable reference of the styling for the sections.
|
||||
///
|
||||
/// *(No equivalent C style function)*
|
||||
pub fn header_channels_mut<'a>(&'a mut self) -> &'a mut NcChannelPair {
|
||||
pub fn header_channels_mut(&mut self) -> &mut NcChannelPair {
|
||||
&mut self.headerchannels
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ impl NcMenuOptions {
|
||||
/// Returns a mutable reference of the styling for the sections.
|
||||
///
|
||||
/// *(No equivalent C style function)*
|
||||
pub fn section_channels_mut<'a>(&'a mut self) -> &'a mut NcChannelPair {
|
||||
pub fn section_channels_mut(&mut self) -> &mut NcChannelPair {
|
||||
&mut self.sectionchannels
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ impl NcProgBar {
|
||||
/// Return a reference to the ncprogbar's underlying ncplane.
|
||||
///
|
||||
/// *C style function: [ncprogbar_plane()][crate::ncprogbar_plane].*
|
||||
pub fn plane<'a>(&'a mut self) -> &'a mut NcPlane {
|
||||
pub fn plane(&mut self) -> &mut NcPlane {
|
||||
unsafe { &mut *crate::ncprogbar_plane(self) }
|
||||
}
|
||||
|
||||
|
@ -16,17 +16,17 @@ impl NcTreeItem {
|
||||
/// Creates an [NcTreeItem].
|
||||
pub fn new(curry: &str, subs: Option<&mut [NcTreeItem]>, subcount: usize) -> Self {
|
||||
if let Some(subs) = subs {
|
||||
return Self {
|
||||
Self {
|
||||
curry: CString::new(curry).unwrap().into_raw() as *mut _ as *mut c_void,
|
||||
subs: subs.as_mut_ptr(),
|
||||
subcount: subcount as u32,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return Self {
|
||||
Self {
|
||||
curry: CString::new(curry).unwrap().into_raw() as *mut _ as *mut c_void,
|
||||
subs: null_mut(),
|
||||
subcount: subcount as u32,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
use core::ptr::null_mut;
|
||||
|
||||
use crate::{
|
||||
error, error_ref_mut, nctree_create, NcError, NcInput, NcPlane, NcResult, NcTree, NcTreeItem,
|
||||
NcTreeOptions, NCRESULT_ERR,
|
||||
@ -38,8 +36,8 @@ impl NcTree {
|
||||
// /// *C style function: [nctree_goto()][crate::nctree_goto].*
|
||||
// pub fn goto(&mut self, spec: ... , failspec: ...) -> NcResult<&mut NcTreeItem> {
|
||||
// let res = unsafe { crate::nctree_goto(self) };
|
||||
// if res != null_mut() {
|
||||
// return Ok(unsafe { &mut *(res as *mut NcTreeItem) });
|
||||
// if !res.is_null() {
|
||||
// Ok(unsafe { &mut *(res as *mut NcTreeItem) })
|
||||
// } else {
|
||||
// Err(NcError::with_msg(NCRESULT_ERR, "NcTree.goto()"))
|
||||
// }
|
||||
@ -53,8 +51,8 @@ impl NcTree {
|
||||
/// *C style function: [nctree_focused()][crate::nctree_focused].*
|
||||
pub fn focused(&mut self) -> NcResult<&mut NcTreeItem> {
|
||||
let res = unsafe { crate::nctree_focused(self) };
|
||||
if res != null_mut() {
|
||||
return Ok(unsafe { &mut *(res as *mut NcTreeItem) });
|
||||
if !res.is_null() {
|
||||
Ok(unsafe { &mut *(res as *mut NcTreeItem) })
|
||||
} else {
|
||||
Err(NcError::with_msg(NCRESULT_ERR, "NcTree.focused()"))
|
||||
}
|
||||
@ -63,10 +61,11 @@ impl NcTree {
|
||||
/// Changes the focus to the next item, and returns it.
|
||||
///
|
||||
/// *C style function: [nctree_next()][crate::nctree_next].*
|
||||
#[allow(clippy::should_implement_trait)]
|
||||
pub fn next(&mut self) -> NcResult<&mut NcTreeItem> {
|
||||
let res = unsafe { crate::nctree_next(self) };
|
||||
if res != null_mut() {
|
||||
return Ok(unsafe { &mut *(res as *mut NcTreeItem) });
|
||||
if !res.is_null() {
|
||||
Ok(unsafe { &mut *(res as *mut NcTreeItem) })
|
||||
} else {
|
||||
Err(NcError::with_msg(NCRESULT_ERR, "NcTree.next()"))
|
||||
}
|
||||
@ -77,8 +76,8 @@ impl NcTree {
|
||||
/// *C style function: [nctree_prev()][crate::nctree_prev].*
|
||||
pub fn prev(&mut self) -> NcResult<&mut NcTreeItem> {
|
||||
let res = unsafe { crate::nctree_prev(self) };
|
||||
if res != null_mut() {
|
||||
return Ok(unsafe { &mut *(res as *mut NcTreeItem) });
|
||||
if !res.is_null() {
|
||||
Ok(unsafe { &mut *(res as *mut NcTreeItem) })
|
||||
} else {
|
||||
Err(NcError::with_msg(NCRESULT_ERR, "NcTree.prev()"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user