String
error is very idiomatic
Actually if what you want is a buffered reader:
use std::path::Path;
use std::io;
// do you really need this lifetime to be 'static ??
fn file_digest(digest_alg: &'static digest::Algorithm, file_path: &Path) -> io::Result<Digest> {
let mut file = try!(io::File::open(file_path));
let mut reader = BufReader::with_capacity(capacity, file);
let mut ctx = digest::Context::new(digest_alg);
for byte in reader.bytes() {
ctx.update(try!(byte));
}
Ok(ctx.finish())
}
Also, your digest
stuff could directly take an Iterator
over bytes ?
use std::path::Path;
use std::io;
fn file_digest(digest_alg: &digest::Algorithm, file_path: &Path) -> io::Result<Digest> {
let mut file = try!(io::File::open(file_path));
let mut reader = io::BufReader::with_capacity(capacity, file);
try!(bytes_digest(digest_alg, reader.bytes()))
}
hi all, I'm using manual(https://doc.rust-lang.org/book) for studying rust but I'm stuck on https://doc.rust-lang.org/book/crates-and-modules.html#exporting-a-public-interface. It doesnt compile with message:
Compiling phrases v0.1.0 (file:///D:/rust/phrases)
src\main.rs:7:38: 7:54 error: unresolved name `greetings::hello` [E0425]
src\main.rs:7 println!("Hello in English: {}", greetings::hello());
^~~~~~~~~~~~~~~~
<std macros>:2:27: 2:58 note: in this expansion of format_args!
<std macros>:3:1: 3:54 note: in this expansion of print! (defined in <std macros>)
src\main.rs:7:5: 7:58 note: in this expansion of println! (defined in <std macros>)
src\main.rs:7:38: 7:54 help: run `rustc --explain E0425` to see a detailed explanation
src\main.rs:8:40: 8:58 error: unresolved name `farewells::goodbye` [E0425]
src\main.rs:8 println!("Goodbye in English: {}", farewells::goodbye());
^~~~~~~~~~~~~~~~~~
<std macros>:2:27: 2:58 note: in this expansion of format_args!
<std macros>:3:1: 3:54 note: in this expansion of print! (defined in <std macros>)
src\main.rs:8:5: 8:62 note: in this expansion of println! (defined in <std macros>)
src\main.rs:8:40: 8:58 help: run `rustc --explain E0425` to see a detailed explanation
error: aborting due to 2 previous errors
error: Could not compile `phrases`.
is it an error in manual or I'm doing something wrong?
mod greetings;
mod farewells;
trait X: Sized {...}
. and make trait-objects &X