causal-agent / scraper

HTML parsing and querying with CSS selectors
https://docs.rs/scraper
ISC License
1.79k stars 98 forks source link

Allow `Selector` to be const-creatable #141

Closed conqp closed 4 months ago

conqp commented 10 months ago

Currently we cannot create const SELECTOR: Selector = ... object, due to Selector::parse not being const. This in turn would require cssparser::Tokenizer::new() and cssparser::Tokenizer::with_first_line_number() to be const as well. I think that this would be possible to do.

adamreichold commented 10 months ago

I am highly sceptical this will be possible soon as this would require things like selectors::parser::SelectorList::parse to be const.

conqp commented 10 months ago

Probably. I'm currently using once_cell::sync::Lazy to work around this limitation.

cfvescovo commented 4 months ago

OnceCell is now part of the standard library: https://github.com/rust-lang/rfcs/pull/2788 I think this should be considered the solution to this issue, since we cannot make Selector const-creatable