Skip to content
4 changes: 4 additions & 0 deletions changelog.d/1608.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The `usage()` method on the `Function` trait is now required. Custom VRL functions must implement this
method to return a `&'static str` describing the function's purpose.

authors: thomasqueirozb
4 changes: 4 additions & 0 deletions src/compiler/expression/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,10 @@ mod tests {
"test"
}

fn usage(&self) -> &'static str {
"Test function"
}

fn examples(&self) -> &'static [crate::compiler::function::Example] {
&[]
}
Expand Down
4 changes: 1 addition & 3 deletions src/compiler/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ pub trait Function: Send + Sync + fmt::Debug {
}

/// A more elaborate multi-paragraph description on how to use the function.
fn usage(&self) -> &'static str {
"TODO"
}
fn usage(&self) -> &'static str;

/// One or more examples demonstrating usage of the function in VRL source
/// code.
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/abs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ impl Function for Abs {
"abs"
}

fn usage(&self) -> &'static str {
"Computes the absolute value of `value`."
}

fn parameters(&self) -> &'static [Parameter] {
&[Parameter {
keyword: "value",
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ impl Function for Append {
"append"
}

fn usage(&self) -> &'static str {
"Appends each item in the `items` array to the end of the `value` array."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ impl Function for Array {
"array"
}

fn usage(&self) -> &'static str {
"Returns `value` if it is an array, otherwise returns an error. This enables the type checker to guarantee that the returned value is an array and can be used in any function that expects an array."
}

fn parameters(&self) -> &'static [Parameter] {
&[Parameter {
keyword: "value",
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ impl Function for Assert {
"assert"
}

fn usage(&self) -> &'static str {
"Asserts the `condition`, which must be a Boolean expression. The program is aborted with `message` if the condition evaluates to `false`."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/assert_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ impl Function for AssertEq {
"assert_eq"
}

fn usage(&self) -> &'static str {
"Asserts that two expressions, `left` and `right`, have the same value. The program is aborted with `message` if they do not have the same value."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/basename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ impl Function for BaseName {
"basename"
}

fn usage(&self) -> &'static str {
"Returns the filename component of the given `path`. This is similar to the Unix `basename` command. If the path ends in a directory separator, the function returns the name of the directory."
}

fn parameters(&self) -> &'static [Parameter] {
&[Parameter {
keyword: "value",
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ impl Function for Boolean {
"bool"
}

fn usage(&self) -> &'static str {
"The value to check if it is a Boolean."
}

fn parameters(&self) -> &'static [Parameter] {
&[Parameter {
keyword: "value",
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/casing/camelcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ impl Function for Camelcase {
"camelcase"
}

fn usage(&self) -> &'static str {
"Takes the `value` string, and turns it into camelCase. Optionally, you can pass in the existing case of the function, or else an attempt is made to determine the case automatically."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/casing/kebabcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ impl Function for Kebabcase {
"kebabcase"
}

fn usage(&self) -> &'static str {
"Takes the `value` string, and turns it into kebab-case. Optionally, you can pass in the existing case of the function, or else we will try to figure out the case automatically."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/casing/pascalcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ impl Function for Pascalcase {
"pascalcase"
}

fn usage(&self) -> &'static str {
"Takes the `value` string, and turns it into PascalCase. Optionally, you can pass in the existing case of the function, or else we will try to figure out the case automatically."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/casing/screamingsnakecase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ impl Function for ScreamingSnakecase {
"screamingsnakecase"
}

fn usage(&self) -> &'static str {
"Takes the `value` string, and turns it into SCREAMING_SNAKE case. Optionally, you can pass in the existing case of the function, or else we will try to figure out the case automatically."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/casing/snakecase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ impl Function for Snakecase {
"snakecase"
}

fn usage(&self) -> &'static str {
"Takes the `value` string, and turns it into snake-case. Optionally, you can pass in the existing case of the function, or else we will try to figure out the case automatically."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/ceil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ impl Function for Ceil {
"ceil"
}

fn usage(&self) -> &'static str {
"Rounds the `value` up to the specified `precision`."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ impl Function for Chunks {
"chunks"
}

fn usage(&self) -> &'static str {
"Chunks `value` into slices of length `chunk_size` bytes."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/community_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ impl Function for CommunityID {
"community_id"
}

fn usage(&self) -> &'static str {
"Generates an ID based on the [Community ID Spec](https://github.com/corelight/community-id-spec)."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ impl Function for Compact {
"compact"
}

fn usage(&self) -> &'static str {
"Compacts the `value` by removing empty values, where empty values are defined using the available parameters."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/contains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ impl Function for Contains {
"contains"
}

fn usage(&self) -> &'static str {
"Determines whether the `value` string contains the specified `substring`."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/contains_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ impl Function for ContainsAll {
"contains_all"
}

fn usage(&self) -> &'static str {
"Determines whether the `value` string contains all the specified `substrings`."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
8 changes: 8 additions & 0 deletions src/stdlib/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,14 @@ impl Function for Crc {
"crc"
}

fn usage(&self) -> &'static str {
indoc! {
"Calculates a CRC of the `value`.The CRC `algorithm` used can be optionally specified.

This function is infallible if either the default `algorithm` value or a recognized-valid compile-time `algorithm` string literal is used. Otherwise, it is fallible."
}
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/decode_base16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ impl Function for DecodeBase16 {
"decode_base16"
}

fn usage(&self) -> &'static str {
"Decodes the `value` (a [Base16](https://en.wikipedia.org/wiki/Hexadecimal) string) into its original string."
}

fn parameters(&self) -> &'static [Parameter] {
&[Parameter {
keyword: "value",
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/decode_base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ impl Function for DecodeBase64 {
"decode_base64"
}

fn usage(&self) -> &'static str {
"Decodes the `value` (a [Base64](https://en.wikipedia.org/wiki/Base64) string) into its original string."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/decode_gzip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ impl Function for DecodeGzip {
"decode_gzip"
}

fn usage(&self) -> &'static str {
"Decodes the `value` (a [Gzip](https://www.gzip.org/) string) into its original string."
}

fn examples(&self) -> &'static [Example] {
&[example! {
title: "Decode Gzip data",
Expand Down
6 changes: 6 additions & 0 deletions src/stdlib/decode_lz4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ impl Function for DecodeLz4 {
"decode_lz4"
}

fn usage(&self) -> &'static str {
"Decodes the `value` (an lz4 string) into its original string. `buf_size` is the size of the buffer to decode into, this must be equal to or larger than the uncompressed size.
If `prepended_size` is set to `true`, it expects the original uncompressed size to be prepended to the compressed data.
`prepended_size` is useful for some implementations of lz4 that require the original size to be known before decoding."
}

fn examples(&self) -> &'static [Example] {
&[
example! {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/decode_mime_q.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ impl Function for DecodeMimeQ {
"decode_mime_q"
}

fn usage(&self) -> &'static str {
"Replaces q-encoded or base64-encoded [encoded-word](https://datatracker.ietf.org/doc/html/rfc2047#section-2)) substrings in the `value` with their original string."
}

fn parameters(&self) -> &'static [Parameter] {
&[Parameter {
keyword: "value",
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/decode_percent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ impl Function for DecodePercent {
"decode_percent"
}

fn usage(&self) -> &'static str {
"Decodes a [percent-encoded](https://url.spec.whatwg.org/#percent-encoded-bytes) `value` like a URL."
}

fn parameters(&self) -> &'static [Parameter] {
&[Parameter {
keyword: "value",
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/decode_punycode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ impl Function for DecodePunycode {
"decode_punycode"
}

fn usage(&self) -> &'static str {
"Decodes a [punycode](https://en.wikipedia.org/wiki/Punycode) encoded `value`, such as an internationalized domain name ([IDN](https://en.wikipedia.org/wiki/Internationalized_domain_name)). This function assumes that the value passed is meant to be used in IDN context and that it is either a domain name or a part of it."
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/decode_snappy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ impl Function for DecodeSnappy {
"decode_snappy"
}

fn usage(&self) -> &'static str {
"Decodes the `value` (a Snappy string) into its original string."
}

fn examples(&self) -> &'static [Example] {
&[example! {
title: "Decode Snappy data",
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/decode_zlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ impl Function for DecodeZlib {
"decode_zlib"
}

fn usage(&self) -> &'static str {
"Decodes the `value` (a [Zlib](https://www.zlib.net) string) into its original string."
}

fn examples(&self) -> &'static [Example] {
&[example! {
title: "Decode Zlib data",
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/decode_zstd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ impl Function for DecodeZstd {
"decode_zstd"
}

fn usage(&self) -> &'static str {
"Decodes the `value` (a [Zstandard](https://facebook.github.io/zstd) string) into its original string."
}

fn examples(&self) -> &'static [Example] {
&[example! {
title: "Decode Zstd data",
Expand Down
41 changes: 41 additions & 0 deletions src/stdlib/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,47 @@ impl Function for Decrypt {
"decrypt"
}

fn usage(&self) -> &'static str {
indoc! {"
Decrypts a string with a symmetric encryption algorithm.

Supported Algorithms:

* AES-256-CFB (key = 32 bytes, iv = 16 bytes)
* AES-192-CFB (key = 24 bytes, iv = 16 bytes)
* AES-128-CFB (key = 16 bytes, iv = 16 bytes)
* AES-256-OFB (key = 32 bytes, iv = 16 bytes)
* AES-192-OFB (key = 24 bytes, iv = 16 bytes)
* AES-128-OFB (key = 16 bytes, iv = 16 bytes)
* AES-128-SIV (key = 32 bytes, iv = 16 bytes)
* AES-256-SIV (key = 64 bytes, iv = 16 bytes)
* Deprecated - AES-256-CTR (key = 32 bytes, iv = 16 bytes)
* Deprecated - AES-192-CTR (key = 24 bytes, iv = 16 bytes)
* Deprecated - AES-128-CTR (key = 16 bytes, iv = 16 bytes)
* AES-256-CTR-LE (key = 32 bytes, iv = 16 bytes)
* AES-192-CTR-LE (key = 24 bytes, iv = 16 bytes)
* AES-128-CTR-LE (key = 16 bytes, iv = 16 bytes)
* AES-256-CTR-BE (key = 32 bytes, iv = 16 bytes)
* AES-192-CTR-BE (key = 24 bytes, iv = 16 bytes)
* AES-128-CTR-BE (key = 16 bytes, iv = 16 bytes)
* AES-256-CBC-PKCS7 (key = 32 bytes, iv = 16 bytes)
* AES-192-CBC-PKCS7 (key = 24 bytes, iv = 16 bytes)
* AES-128-CBC-PKCS7 (key = 16 bytes, iv = 16 bytes)
* AES-256-CBC-ANSIX923 (key = 32 bytes, iv = 16 bytes)
* AES-192-CBC-ANSIX923 (key = 24 bytes, iv = 16 bytes)
* AES-128-CBC-ANSIX923 (key = 16 bytes, iv = 16 bytes)
* AES-256-CBC-ISO7816 (key = 32 bytes, iv = 16 bytes)
* AES-192-CBC-ISO7816 (key = 24 bytes, iv = 16 bytes)
* AES-128-CBC-ISO7816 (key = 16 bytes, iv = 16 bytes)
* AES-256-CBC-ISO10126 (key = 32 bytes, iv = 16 bytes)
* AES-192-CBC-ISO10126 (key = 24 bytes, iv = 16 bytes)
* AES-128-CBC-ISO10126 (key = 16 bytes, iv = 16 bytes)
* CHACHA20-POLY1305 (key = 32 bytes, iv = 12 bytes)
* XCHACHA20-POLY1305 (key = 32 bytes, iv = 24 bytes)
* XSALSA20-POLY1305 (key = 32 bytes, iv = 24 bytes)
"}
}

fn parameters(&self) -> &'static [Parameter] {
&[
Parameter {
Expand Down
Loading
Loading