env.rs: rename flags::EnvMode to EnvMode

The "flags" module was introduced when these where standalone constants.
Now that we define them as bitflags, we no longer need the extra namespace.
This commit is contained in:
Johannes Altmanninger 2023-04-08 09:24:30 +02:00
parent 8e5adbf237
commit 11e16ef6df
5 changed files with 50 additions and 45 deletions

View File

@ -5,8 +5,8 @@ use crate::builtins::shared::{
STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use crate::common::{escape_string, valid_func_name, EscapeStringStyle};
use crate::env::flags::EnvMode;
use crate::env::status::{ENV_NOT_FOUND, ENV_OK};
use crate::env::EnvMode;
use crate::ffi::parser_t;
use crate::re::{regex_make_anchored, to_boxed_chars};
use crate::wchar::{wstr, L};

View File

@ -4,7 +4,7 @@ use libc::c_int;
use crate::{
builtins::shared::{io_streams_t, BUILTIN_ERR_ARG_COUNT1},
env::flags::EnvMode,
env::EnvMode,
ffi::parser_t,
wchar::{wstr, WString, L},
wchar_ffi::{WCharFromFFI, WCharToFFI},

View File

@ -1,47 +1,52 @@
/// Flags that may be passed as the 'mode' in env_stack_t::set() / environment_t::get().
pub mod flags {
use autocxx::c_int;
use bitflags::bitflags;
//! Prototypes for functions for manipulating fish script variables.
bitflags! {
/// Flags that may be passed as the 'mode' in env_stack_t::set() / environment_t::get().
#[repr(C)]
pub struct EnvMode: u16 {
/// Default mode. Used with `env_stack_t::get()` to indicate the caller doesn't care what scope
/// the var is in or whether it is exported or unexported.
const DEFAULT = 0;
/// Flag for local (to the current block) variable.
const LOCAL = 1 << 0;
const FUNCTION = 1 << 1;
/// Flag for global variable.
const GLOBAL = 1 << 2;
/// Flag for universal variable.
const UNIVERSAL = 1 << 3;
/// Flag for exported (to commands) variable.
const EXPORT = 1 << 4;
/// Flag for unexported variable.
const UNEXPORT = 1 << 5;
/// Flag to mark a variable as a path variable.
const PATHVAR = 1 << 6;
/// Flag to unmark a variable as a path variable.
const UNPATHVAR = 1 << 7;
/// Flag for variable update request from the user. All variable changes that are made directly
/// by the user, such as those from the `read` and `set` builtin must have this flag set. It
/// serves one purpose: to indicate that an error should be returned if the user is attempting
/// to modify a var that should not be modified by direct user action; e.g., a read-only var.
const USER = 1 << 8;
}
}
use autocxx::c_int;
use bitflags::bitflags;
impl From<EnvMode> for c_int {
fn from(val: EnvMode) -> Self {
c_int(i32::from(val.bits()))
}
// Limit `read` to 100 MiB (bytes not wide chars) by default. This can be overridden by the
// fish_read_limit variable.
const DEFAULT_READ_BYTE_LIMIT: usize = 100 * 1024 * 1024;
pub static mut read_byte_limit: usize = DEFAULT_READ_BYTE_LIMIT;
pub static mut curses_initialized: bool = true;
bitflags! {
/// Flags that may be passed as the 'mode' in env_stack_t::set() / environment_t::get().
#[repr(C)]
pub struct EnvMode: u16 {
/// Default mode. Used with `env_stack_t::get()` to indicate the caller doesn't care what scope
/// the var is in or whether it is exported or unexported.
const DEFAULT = 0;
/// Flag for local (to the current block) variable.
const LOCAL = 1 << 0;
const FUNCTION = 1 << 1;
/// Flag for global variable.
const GLOBAL = 1 << 2;
/// Flag for universal variable.
const UNIVERSAL = 1 << 3;
/// Flag for exported (to commands) variable.
const EXPORT = 1 << 4;
/// Flag for unexported variable.
const UNEXPORT = 1 << 5;
/// Flag to mark a variable as a path variable.
const PATHVAR = 1 << 6;
/// Flag to unmark a variable as a path variable.
const UNPATHVAR = 1 << 7;
/// Flag for variable update request from the user. All variable changes that are made directly
/// by the user, such as those from the `read` and `set` builtin must have this flag set. It
/// serves one purpose: to indicate that an error should be returned if the user is attempting
/// to modify a var that should not be modified by direct user action; e.g., a read-only var.
const USER = 1 << 8;
}
impl From<EnvMode> for u16 {
fn from(val: EnvMode) -> Self {
val.bits()
}
}
impl From<EnvMode> for c_int {
fn from(val: EnvMode) -> Self {
c_int(i32::from(val.bits()))
}
}
impl From<EnvMode> for u16 {
fn from(val: EnvMode) -> Self {
val.bits()
}
}

View File

@ -4,7 +4,7 @@ use crate::wchar_ffi::WCharToFFI;
use ::std::pin::Pin;
#[rustfmt::skip]
use ::std::slice;
use crate::env::flags::EnvMode;
use crate::env::EnvMode;
pub use crate::wait_handle::{
WaitHandleRef, WaitHandleRefFFI, WaitHandleStore, WaitHandleStoreFFI,
};

View File

@ -1,6 +1,6 @@
// Support for exposing the terminal size.
use crate::common::assert_sync;
use crate::env::flags::EnvMode;
use crate::env::EnvMode;
use crate::ffi::{environment_t, parser_t, Repin};
use crate::flog::FLOG;
use crate::wchar::{WString, L};