Skip to content

Make invalid selectors crash at compile time #1

@zexa

Description

@zexa
#[derive(de_hypertext::Deserialize)]
struct MyStruct {
    #[de_hypertext(selector = "a")]
    field1: String,
}

The derive macro generates the following snippet

document
    .select(
        &de_hypertext::scraper::Selector::parse("a")
            .map_err(|_| {
                de_hypertext::DeserializeError::BuildingSelectorFailed {
                    struct_name: std::any::type_name::<Self>().to_string(),
                    field: "field1".to_string(),
                    selector: "a".to_string(),
                }
            })?,
    )

However, this code will only check if the selector is valid at runtime. Since we specify the selectors when writing the code, couldn't we check if the selectors are valid at compile time?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions