กล่องค้นหาไฟล์ที่รวดเร็วอย่างเหลือเชื่อที่สร้างใน Rust
กรุณารายงานปัญหาใด ๆ ที่คุณพบเมื่อใช้การค้นหาสนิมที่นี่: ปัญหา
เพิ่ม rust_search = "2.0.0"
ใน Cargo.toml
[ dependencies ]
rust_search = " 2.0.0 "
use rust_search :: SearchBuilder ;
fn main ( ) {
let search : Vec < String > = SearchBuilder :: default ( )
. location ( "~/path/to/directory" )
. search_input ( "what to search" )
. more_locations ( vec ! [ "/anotherPath/to/search" , "/keepAddingIfYouWant/" ] )
. limit ( 1000 ) // results to return
. ext ( "extension" )
. strict ( )
. depth ( 1 )
. ignore_case ( )
. hidden ( )
. build ( )
. collect ( ) ;
for path in search {
println ! ( "{}" , path ) ;
}
}
use rust_search :: { SearchBuilder , similarity_sort } ;
fn main ( ) {
let search_input = "fly" ;
let mut search : Vec < String > = SearchBuilder :: default ( )
. location ( "~/Desktop/" )
. search_input ( search_input )
. depth ( 1 )
. ignore_case ( )
. build ( )
. collect ( ) ;
similarity_sort ( & mut search , & search_input ) ;
for path in search {
println ! ( "{:?}" , path ) ;
}
}
ค้นหา โดยไม่ เรียงลำดับความคล้ายคลึงกัน
["afly.txt", "bfly.txt", "flyer.txt", "fly.txt"]
ค้นหา ด้วย การเรียงลำดับที่คล้ายกัน
["fly.txt", "flyer.txt", "afly.txt", "bfly.txt",]
use rust_search :: SearchBuilder ;
let files : Vec < String > = SearchBuilder :: default ( )
. location ( "/path/to/directory" )
. ext ( "file_extension" )
. build ( )
. collect ( ) ;
use rust_search :: SearchBuilder ;
let files : Vec < String > = SearchBuilder :: default ( )
. location ( "/path/to/directory" )
. depth ( 1 )
. build ( )
. collect ( ) ;
หากต้องการกรองไฟล์ตาม date_created, date_modified, file_size และ/หรือ custom_filter ให้ใช้:
use rust_search :: { FileSize , FilterExt , SearchBuilder } ;
use std :: time :: { Duration , SystemTime } ;
let search : Vec < String > = SearchBuilder :: default ( )
. location ( "~/path/to/directory" )
. file_size_greater ( FileSize :: Kilobyte ( 200.0 ) )
. file_size_smaller ( FileSize :: Megabyte ( 10.0 ) )
. created_after ( SystemTime :: now ( ) - Duration :: from_secs ( 3600 * 24 * 10 ) )
. created_before ( SystemTime :: now ( ) )
. modified_after ( SystemTime :: now ( ) - Duration :: from_secs ( 3600 * 24 * 5 ) )
. custom_filter ( |dir| dir . metadata ( ) . unwrap ( ) . is_file ( ) )
. custom_filter ( |dir| !dir . metadata ( ) . unwrap ( ) . permissions ( ) . readonly ( ) )
. build ( )
. collect ( ) ;
สำหรับตัวอย่างเพิ่มเติม โปรดดูที่เอกสารประกอบ
ขนาดตัวอย่างที่แตกต่างกันนั้นเกิดจากการที่ fd และ glob เป็นเครื่องมือที่แตกต่างกันและมีกรณีการใช้งานที่แตกต่างกัน fd เป็นเครื่องมือบรรทัดคำสั่งที่ใช้ค้นหาไฟล์และไดเร็กทอรี glob เป็นไลบรารี่ที่ใช้ค้นหาไฟล์และไดเร็กทอรี การวัดประสิทธิภาพทำได้บน MacBook Air M2, หน่วยความจำ Unified ขนาด 16 GB
การวัดประสิทธิภาพเสร็จสิ้นโดยใช้ไฮเปอร์ไฟน์ ไฟล์การวัดประสิทธิภาพจะอยู่ในโฟลเดอร์ไดรฟ์การวัดประสิทธิภาพ
การวัดประสิทธิภาพเสร็จสิ้นในไดเร็กทอรีที่มีไฟล์ 300,000 ไฟล์
คำสั่ง / ไลบรารี | วิธี] | ขั้นต่ำ [s] | สูงสุด [วินาที] | ญาติ |
---|---|---|---|---|
rust_search | 1.317 ± 0.002 | 1.314 | 1.320 | 1.00 น |
glob | 22.728 ± 0.023 | 22.690 | 22.746 | 17.25 ± 0.03 |
การวัดประสิทธิภาพเสร็จสิ้นในไดเร็กทอรีที่มีไฟล์ 45K
คำสั่ง / ไลบรารี | ค่าเฉลี่ย [มิลลิวินาที] | นาที [ms] | สูงสุด [มิลลิวินาที] | ญาติ |
---|---|---|---|---|
rust_search | 680.5 ± 2.1 | 678.3 | 683.6 | 1.00 น |
fd -e .js | 738.7 ± 10.2 | 720.8 | 746.7 | 1.09 ± 0.02 |
+ rust_search is 17.25 times faster than Glob.
+ rust_search** is 1.09 times faster than FD.
การสนับสนุนใดๆ จะมีคุณค่าอย่างมากเนื่องจากห้องสมุดแห่งนี้ยังอยู่ในช่วงเริ่มต้น
หากคุณต้องการมีส่วนร่วมในโครงการนี้ โปรดทำตามขั้นตอนด้านล่าง:
โครงการนี้ได้รับอนุญาตภายใต้เงื่อนไขของใบอนุญาต MIT
คลิกปุ่มด้านล่างเพื่อเข้าร่วมเซิร์ฟเวอร์ discord หรือ Linkedin