Tabbas, a nan za mu tafi!
Tsatsa shine yaren shirye-shiryen tsarin multiparadigm wanda aka mayar da hankali kan aiki da aminci, musamman amintaccen haษin gwiwa. ฦirar sa yana sa ya zama mai amfani ga abubuwa da yawa, amma ya dace sosai don ayyukan tsarin da aka rubuta a C ko C++. A yau, zan tattauna hanyar ฦirฦirar babban fayil a cikin Rust.
ฦirฦirar babban fayil aiki ne mai sauฦi a cikin Tsatsa wanda za'a iya samu ta amfani da daidaitaccen tsarin tsarin fayil ษin ษakin karatu, musamman aikin `create_dir_all`.
**Aiki:** std:: fs:: halitta_dir_all
Wannan aikin yana ฦirฦira kai-tsaye da duk abubuwan haษin mahaifansa idan sun ษace.
amfani da std::fs;
fn main () -> std:: io:: sakamako <()> {
fs :: ฦirฦirar_dir_all ("/ wasu / hanya")?;
Ko(())
}
Bari mu rarraba lambar mataki-mataki.
Layin farko `amfani std :: fs;` yana shigo da tsarin tsarin fayil daga daidaitaccen ษakin karatu na Rust. Wannan tsarin ya ฦunshi ayyuka da yawa don mu'amala da tsarin fayil, gami da ฦirฦira da share kundayen adireshi, karantawa da rubuta fayiloli, da karanta metadata.
An bayyana aikin 'babban' tare da 'fn main() -> std:: io:: sakamako <()>'. Wannan wuri ne na musamman don shirin Tsatsa. Nau'in dawowa anan, `std :: io :: Sakamako <()>`, Rust enum ne wanda ke wakiltar ko dai nasara (`Ok`) ko gazawa (`Err`).
Layi na gaba fs :: ฦirฦirar_dir_all ("/ wasu / hanya")?; shine inda ainihin kundin kundin adireshi ya faru. Aikin `create_dir_all` yana ษaukar hanyar fayil kuma yana ฦoฦarin ฦirฦirar shi. Hakanan zai ฦirฦiri duk kundayen adireshi na iyaye da suka ษace. Mai aiki na `?` yana yada duk wani kurakurai da suka faru yayin ฦirฦirar kundin adireshi, yana sa aikin ya dawo da wuri tare da ฦimar kuskure.
A ฦarshe, Ok()) ana dawowa don nuna rashin kurakurai yayin aiwatarwa.
Kara karantawa