Skip to content

header

The two-line source header that carries a copyright notice and an SPDX license identifier.

Copyright (C) 2025 Jane Doe
SPDX-License-Identifier: MIT

The text has no comment marker, so prefix each line for the language of the file (// , # , …). The REUSE specification and most license scanners read exactly these two lines. Nothing is validated: years can be "2025" or "2020-2025", and expression any SPDX expression (see Expression).

use helpers4::license::header;

Cargo feature license (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features license

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.6", default-features = false, features = ["license"] }
pub fn header(holder: &str, years: &str, expression: &str) -> String
ParameterTypeDescription
holder&strThe copyright holder, such as a name or an organization.
years&strThe year or range of years of the notice.
expression&strThe SPDX license identifier or expression.

String — The two lines, without a trailing newline.

use helpers4::license::header;

let header = header("Jane Doe", "2025", "MIT OR Apache-2.0");
assert_eq!(header, "Copyright (C) 2025 Jane Doe\nSPDX-License-Identifier: MIT OR Apache-2.0");
let commented: Vec<String> = header.lines().map(|line| format!("// {line}")).collect();
assert_eq!(commented[1], "// SPDX-License-Identifier: MIT OR Apache-2.0");

src/license/header.rs