Skip to content

Commit 27b6e04

Browse files
committed
Add rust lib for PURL validation using prebuilt FST
Signed-off-by: Keshav Priyadarshi <[email protected]>
1 parent 0ba5b37 commit 27b6e04

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "purl_validator"
3+
version = "0.1.0"
4+
edition = "2024"
5+
authors = ["Keshav Priyadarshi <[email protected]>", "AboutCode <[email protected]>"]
6+
description = "PackageURL validator using prebuilt FST"
7+
license = "Apache-2.0"
8+
repository = "https://github.com/aboutcode-org/purl-validator"
9+
10+
[lib]
11+
name = "purl_validator"
12+
crate-type = ["rlib"]
13+
14+
[dependencies]
15+
fst = "0.4.7"
16+
once_cell = "1.21"
17+
18+
[[bin]]
19+
name = "fst_builder"
20+
path = "fst_builder/main.rs"
21+
22+
include = [
23+
"src/**",
24+
"purls.fst",
25+
"Cargo.toml",
26+
"README.md",
27+
"LICENSE"
28+
]

purls.fst

69 Bytes
Binary file not shown.

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use fst::Set;
2+
use once_cell::sync::Lazy;
3+
4+
5+
static FST_BYTES: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/purls.fst"));
6+
7+
static VALIDATOR: Lazy<Set<&[u8]>> = Lazy::new(|| {
8+
Set::new(FST_BYTES).expect("Failed to load FST from embedded bytes")
9+
});
10+
11+
12+
pub fn validate(word: &str) -> bool {
13+
VALIDATOR.contains(word)
14+
}
15+

0 commit comments

Comments
 (0)