#------------------------------------------------------------------------------
# $File: rust,v 1.2 2022/11/18 15:58:15 christos Exp $
# Magic for Rust and related languages programs
#
# Rust compiler metadata
# From: Alexandre Iooss <erdnaxe@crans.org>
# URL: https:0 string rust\x00\x00\x00
>12 string \014rustc\x20 Rust compiler metadata
!:ext rmeta
!:mime application/x-rust-metadata
>>7 byte x \b, version %d
# Rust compiler metadata updated with new layout
# From: Quentin Jérôme <quentin.jerome@circl.lu>
# Reference: https:0 string rust\x00\x00\x00
>0x11 string rustc Rust compiler metadata
# version number
>>0x7 byte x , version %d
!:ext rmeta
!:mime application/x-rust-metadata
>>0x10 pstring x \b, %s
# Rust incremental compilation metadata
# From: Alexandre Iooss <erdnaxe@crans.org>
# URL: https:0 string RSIC
>4 uleshort =0 Rust incremental compilation metadata
!:ext bin
>>6 pstring x \b, rustc %s
# Rust source text identification
# From: Quentin Jérôme <quentin.jerome@circl.lu>
# we try to search for crate level attribute
0 string #![
>&0 regex/1l \\w+\\s?.*?\\]$
>>0 use rust-src
# we search for rust keywords in the first 4096 bytes
# don't put the question mark on macro_rules otherwise we don't match \b
0 regex/4096s \\b(impl|fn|macro_rules)\\b
# sometimes impl lines are quite long, searching on 3 lines increases
# the number of bytes read in the tested value to 240 bytes
>&0 regex/3l impl(<.*?>)?(\\s+[a-zA-Z0-9_:]+\\s+for)?\\s+[a-zA-Z0-9_]+.*?
>>0 use rust-src
>&0 regex/1l fn\\s+[a-zA-Z0-9_]+(<.*?>)?\\(
>>0 use rust-src
>&0 string macro_rules!
>>0 use rust-src
0 name rust-src Rust source code text
!:ext rs
!:mime text/x-rust