mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-25 23:21:15 -03:00
util: extract into new crate
Move `src/util.rs` into a new dedicated crate. Closes #12316
This commit is contained in:
committed by
Johannes Altmanninger
parent
f1d78103e4
commit
97e0eda477
9
Cargo.lock
generated
9
Cargo.lock
generated
@@ -168,6 +168,7 @@ dependencies = [
|
||||
"fish-gettext-mo-file-parser",
|
||||
"fish-printf",
|
||||
"fish-tempfile",
|
||||
"fish-util",
|
||||
"fish-wcstringutil",
|
||||
"fish-widecharwidth",
|
||||
"fish-widestring",
|
||||
@@ -285,6 +286,14 @@ dependencies = [
|
||||
"rand 0.9.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fish-util"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"fish-widestring",
|
||||
"rand 0.9.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fish-wcstringutil"
|
||||
version = "0.0.0"
|
||||
|
||||
@@ -26,6 +26,7 @@ fish-gettext-maps = { path = "crates/gettext-maps" }
|
||||
fish-gettext-mo-file-parser = { path = "crates/gettext-mo-file-parser" }
|
||||
fish-printf = { path = "crates/printf", features = ["widestring"] }
|
||||
fish-tempfile = { path = "crates/tempfile" }
|
||||
fish-util = { path = "crates/util" }
|
||||
fish-wcstringutil = { path = "crates/wcstringutil" }
|
||||
fish-widecharwidth = { path = "crates/widecharwidth" }
|
||||
fish-widestring = { path = "crates/widestring" }
|
||||
@@ -102,6 +103,7 @@ fish-gettext = { workspace = true, optional = true }
|
||||
fish-gettext-extraction = { workspace = true, optional = true }
|
||||
fish-printf.workspace = true
|
||||
fish-tempfile.workspace = true
|
||||
fish-util.workspace = true
|
||||
fish-wcstringutil.workspace = true
|
||||
fish-widecharwidth.workspace = true
|
||||
fish-widestring.workspace = true
|
||||
|
||||
14
crates/util/Cargo.toml
Normal file
14
crates/util/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "fish-util"
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
version = "0.0.0"
|
||||
repository.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
fish-widestring.workspace = true
|
||||
rand.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -239,7 +239,7 @@ fn wcsfilecmp_leading_digits(a: &wstr, b: &wstr) -> (Ordering, usize, usize) {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use fish::util::find_subslice;
|
||||
/// use fish_util::find_subslice;
|
||||
/// let haystack = b"ABC ABCDAB ABCDABCDABDE";
|
||||
///
|
||||
/// assert_eq!(find_subslice(b"ABCDABD", haystack), Some(15));
|
||||
@@ -6,12 +6,12 @@
|
||||
use super::prelude::*;
|
||||
use crate::nix::{getegid, geteuid};
|
||||
use crate::path::path_apply_working_directory;
|
||||
use crate::util::wcsfilecmp_glob;
|
||||
use crate::wutil::{
|
||||
INVALID_FILE_ID, file_id_for_path, lwstat, normalize_path, waccess, wbasename, wdirname,
|
||||
wrealpath, wstat,
|
||||
};
|
||||
use bitflags::bitflags;
|
||||
use fish_util::wcsfilecmp_glob;
|
||||
use fish_wcstringutil::split_string_tok;
|
||||
use libc::{F_OK, PATH_MAX, R_OK, S_ISGID, S_ISUID, W_OK, X_OK, mode_t};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::prelude::*;
|
||||
|
||||
use crate::util::get_seeded_rng;
|
||||
use crate::wutil;
|
||||
use fish_util::get_seeded_rng;
|
||||
use rand::rngs::SmallRng;
|
||||
use rand::{Rng, RngCore};
|
||||
use std::sync::{LazyLock, Mutex};
|
||||
|
||||
@@ -527,7 +527,7 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> B
|
||||
}
|
||||
}
|
||||
STATUS_LIST_FILES => {
|
||||
use crate::util::wcsfilecmp_glob;
|
||||
use fish_util::wcsfilecmp_glob;
|
||||
let mut paths = vec![];
|
||||
let mut add = |arg| {
|
||||
let arg = crate::common::wcs2bytes(arg);
|
||||
|
||||
@@ -1382,7 +1382,7 @@ mod tests {
|
||||
ENCODE_DIRECT_END, ESCAPE_TEST_CHAR, EscapeFlags, EscapeStringStyle, UnescapeStringStyle,
|
||||
bytes2wcstring, escape_string, unescape_string, wcs2bytes,
|
||||
};
|
||||
use crate::util::get_seeded_rng;
|
||||
use fish_util::get_seeded_rng;
|
||||
use fish_widestring::{ENCODE_DIRECT_BASE, L, WString, wstr};
|
||||
use rand::{Rng, RngCore};
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@
|
||||
common::charptr2wcstring,
|
||||
localization::{LocalizableString, localizable_string},
|
||||
reader::{get_quote, is_backslashed},
|
||||
util::wcsfilecmp,
|
||||
};
|
||||
use bitflags::bitflags;
|
||||
use fish_util::wcsfilecmp;
|
||||
use fish_wcstringutil::{
|
||||
StringFuzzyMatch, string_fuzzy_match_string, string_prefixes_string,
|
||||
string_prefixes_string_case_insensitive, string_suffixes_string_case_insensitive,
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
};
|
||||
use crate::path::path_apply_working_directory;
|
||||
use crate::prelude::*;
|
||||
use crate::util::wcsfilecmp_glob;
|
||||
use crate::wildcard::{ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE, WildcardResult};
|
||||
use crate::wildcard::{wildcard_expand_string, wildcard_has_internal};
|
||||
use crate::wutil::{Options, normalize_path, wcstoi_partial};
|
||||
use bitflags::bitflags;
|
||||
use fish_common::{EXPAND_RESERVED_BASE, EXPAND_RESERVED_END};
|
||||
use fish_util::wcsfilecmp_glob;
|
||||
use fish_wcstringutil::{join_strings, trim};
|
||||
use fish_widestring::char_offset;
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
@@ -61,10 +61,10 @@
|
||||
path::{path_get_config, path_get_data, path_is_valid},
|
||||
prelude::*,
|
||||
threads::assert_is_background_thread,
|
||||
util::find_subslice,
|
||||
wildcard::{ANY_STRING, wildcard_match},
|
||||
wutil::{FileId, INVALID_FILE_ID, file_id_for_file, wrealpath, wstat, wunlink},
|
||||
};
|
||||
use fish_util::find_subslice;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum SearchType {
|
||||
|
||||
@@ -73,7 +73,6 @@
|
||||
pub mod trace;
|
||||
pub mod tty_handoff;
|
||||
pub mod universal_notifier;
|
||||
pub mod util;
|
||||
pub mod wait_handle;
|
||||
pub mod wgetopt;
|
||||
pub mod wildcard;
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
use crate::prelude::*;
|
||||
use crate::proc::{JobGroupRef, JobList, JobRef, Pid, ProcStatus, job_reap};
|
||||
use crate::signal::{Signal, signal_check_cancel, signal_clear_cancel};
|
||||
use crate::util::get_time;
|
||||
use crate::wait_handle::WaitHandleStore;
|
||||
use crate::wutil::perror;
|
||||
use crate::{flog, flogf, function};
|
||||
use fish_util::get_time;
|
||||
use fish_widestring::WExt;
|
||||
use libc::c_int;
|
||||
use std::cell::{Ref, RefCell, RefMut};
|
||||
|
||||
Reference in New Issue
Block a user