Skip to content

Excellent work but you need to be clearer on your documentation. #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jymchng opened this issue Dec 23, 2024 · 1 comment
Open

Excellent work but you need to be clearer on your documentation. #49

jymchng opened this issue Dec 23, 2024 · 1 comment

Comments

@jymchng
Copy link

jymchng commented Dec 23, 2024

You're solving a huge problem in the industry that many are facing, great work!

However, for this short snippet:

use codesnap::config::{CodeSnap, WatermarkBuilder};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    CodeSnap::default()
        .code("fn main() { println!(\"Hello, world!\"); }")
        .watermark(WatermarkBuilder::default().content("CodeSnap").build()?)
        .build()?
        .create_snapshot()?.raw_data()?.copy()?;
    
    Ok(())
}

I get this error:

> cargo check
    Checking rust-codesnap v0.1.0 (C:\development\rust-codesnap)
error[E0277]: the trait bound `Code: From<&str>` is not satisfied
   --> src/main.rs:5:15
    |
5   |         .code("fn main() { println!(\"Hello, world!\"); }")
    |          ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&str>` is not implemented for `Code`, which is required by `&str: Into<Code>`
    |          |
    |          required by a bound introduced by this call
    |
    = help: the trait `Into<RgbaColor>` is implemented for `&str`
    = help: for that trait implementation, expected `RgbaColor`, found `Code`
    = note: required for `&str` to implement `Into<Code>`
note: required by a bound in `CodeSnap::code`
   --> C:\Users\398334\.cargo\registry\src\index.crates.io-6f17d22bba15001f\codesnap-0.8.3\src\config.rs:281:17
    |
281 | #[derive(Clone, Builder, Serialize, Deserialize, Debug)]
    |                 ^^^^^^^ required by this bound in `CodeSnap::code`
...
290 |     pub code: Code,
    |         ---- required by a bound in this associated function
    = note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `rust-codesnap` (bin "rust-codesnap") due to 1 previous error

which I guess is kind of unfortunate because I don't see how I can fix it - thank you.

@mistricky
Copy link
Member

Hey @jymchng, base on your example, the correct way should be as follow:

use codesnap::config::{CodeBuilder, CodeSnap, WatermarkBuilder};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    CodeSnap::default()
        .code(
            CodeBuilder::default()
                .content("fn main() { println!(\"Hello, World!\"); }")
                .build()?,
        )
        .watermark(WatermarkBuilder::default().content("CodeSnap").build()?)
        .build()?
        .create_snapshot()?
        .raw_data()?
        .copy()?;

    Ok(())
}

You should use Code instead of &str, but the document for the CodeSnap library is indeed lack, I will complete it in future versions, thx for the issue report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants