pub fn is_generated(buf: &[u8]) -> boolExpand description
Returns true when buf looks like generated code: its leading window
(first ~50 lines or first 5 KiB, whichever is smaller) contains a known
marker phrase. Matching is case-insensitive for the marker and never
allocates on the negative path.
Recognized markers:
@generated— Facebook / Meta convention, also used by buck2, rustfmt, and prettier.DO NOT EDIT— Go’sCode generated by ... DO NOT EDIT.is the canonical form; the bare phrase is also widely copied.GENERATED CODE— Lizard’s marker, preserved for compatibility.
Detection runs against raw bytes before parsing, so callers can discard
generated files without paying tree-sitter parse cost. Non-UTF-8 input
will not panic — regex::bytes::Regex operates on the raw byte slice.
§Examples
use big_code_analysis::is_generated;
assert!(is_generated(b"// @generated\nfn x() {}\n"));
assert!(is_generated(
b"// Code generated by protoc. DO NOT EDIT.\npackage x\n",
));
assert!(!is_generated(b"fn main() { /* not generated */ }\n"));§Panics
Panics if the embedded marker regex set fails to build; the marker list is a static literal so this represents a compile-time bug, not a runtime input that can be handled.