This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-03
Channels
- # adventofcode (91)
- # announcements (7)
- # aws (3)
- # babashka (69)
- # beginners (46)
- # calva (30)
- # cider (12)
- # clj-kondo (88)
- # cljs-dev (11)
- # cljsrn (1)
- # clojure (195)
- # clojure-dev (21)
- # clojure-europe (2)
- # clojure-italy (13)
- # clojure-nl (56)
- # clojure-spec (4)
- # clojure-sweden (6)
- # clojure-uk (27)
- # clojurescript (179)
- # core-async (2)
- # cryogen (1)
- # cursive (2)
- # data-science (1)
- # datomic (57)
- # fulcro (15)
- # graalvm (9)
- # instaparse (6)
- # joker (18)
- # juxt (9)
- # leiningen (6)
- # off-topic (20)
- # other-languages (10)
- # pathom (5)
- # re-frame (20)
- # reitit (2)
- # rewrite-clj (5)
- # shadow-cljs (78)
- # sql (34)
- # tools-deps (128)
- # uncomplicate (16)
- # vim (6)
how do I make this compile in Rust?
use walkdir::WalkDir;
fn print() {
for entry in WalkDir::new("foo") {
println!("{}", entry?.path().display());
};
}
fn main() {
print();
}
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
--> src/main.rs:5:24
|
5 | println!("{}", entry?.path().display());
| ^^^^^^ cannot use the `?` operator in a function that returns `()
`This worked!
use walkdir::WalkDir;
use std::io;
fn print() -> Result<(), io::Error> {
for entry in WalkDir::new(".") {
println!("{}", entry?.path().display());
};
return Ok(());
}
fn main() {
let _ = print();
}
4
It a bit rusty, but I think instead use entry.expect("empty entry").path.display()
might be better, Don't make much sense to return an error and do nothing with it, but it probably will not be called anyway.
@gklijs it came from here: https://rust-lang-nursery.github.io/rust-cookbook/file/dir.html