Few curiosity questions

⚓ rust    📅 2025-06-19    👤 surdeus    👁️ 2      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Few curiosity questions

I do not use any crates having dependencies. So recently I tried the color crate, having just one optional dependency. It has some strange things, but I became curious about the following code:

 let binding = "strikethrough".strikethrough();
    let color = binding.green();
    println!("{} and {}", color, "italic".italic().red());

Why I can chain applying color attributes to a string as a part of println, but if I want to do the same out of println, I have to apply attributes separately?

Another question isn't related to the crate, but also very weird. Why do I get the warning?

warning: unused variable: `err`
    --> docgi.rs:1203:13
     |
1203 |         Err(err) => { // probably symlink, skip
     |             ^^^ help: if this is intentional, prefix it with an underscore: `_err`
     |
     = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

I actually use the err in the code,

 let meta = match path.metadata() {
        Ok(metadata) => metadata,
        Err(err) => { // probably symlink, skip
            eprintln!("No metadata for {path:?} {err:?}"); 
            buf.push_str("\", \"type\": \"dead\"}");
            return Ok(buf)},
    };

10 posts - 3 participants

Read full topic

🏷️ rust_feed