From cb256f0ce407290862bbef3f3ef446e1bca1d178 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Mon, 3 Jan 2022 21:22:22 -0500 Subject: [PATCH] Change help strings to const --- src/help.rs | 17 +++++++---------- src/repl.rs | 6 +++--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/help.rs b/src/help.rs index b5f32e5..5d8bf57 100644 --- a/src/help.rs +++ b/src/help.rs @@ -1,16 +1,15 @@ /// Standard help string containing usage information for MPS. -pub fn help() -> String { +pub const HELP_STRING: &str = "This language is all about iteration. Almost everything is an iterator or operates on iterators. By default, any operation which is not an assignment will cause the script runner to handle (play/save) the items which that statement contains. -To view the currently-supported operations, try ?functions and ?filters".to_string() -} +To view the currently-supported operations, try ?functions and ?filters"; -pub fn functions() -> String { +pub const FUNCTIONS: &str = "FUNCTIONS (?functions) Similar to most other languages: function_name(param1, param2, etc.) sql_init(generate = true|false, folder = `path/to/music`) - Initialize the SQLite database connection using the provided parameters. This must be performed before any other database operation (otherwise the database will be connected with default settings). + Initialize the SQLite database connection using the provided parameters. This must be performed before any other database operation (otherwise the database will already be connected with default settings). sql(`SQL query here`) Perform a raw SQLite query on the database which MPS auto-generates. An iterator of the results is returned. @@ -31,10 +30,9 @@ Similar to most other languages: function_name(param1, param2, etc.) Repeat the iterable count times, or infinite times if count is omitted. files(folder = `path/to/music`, recursive = true|false, regex = `pattern`) - Retrieve all files from a folder, matching a regex pattern.".to_string() -} + Retrieve all files from a folder, matching a regex pattern."; -pub fn filters() -> String { +pub const FILTERS: &str = "FILTERS (?filters) Operations to reduce the items in an iterable: iterable.(filter) @@ -46,5 +44,4 @@ Operations to reduce the items in an iterable: iterable.(filter) Compare all items, keeping only those that match the condition. [empty] - Matches all items".to_string() -} + Matches all items"; diff --git a/src/repl.rs b/src/repl.rs index 8e1309f..6e90416 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -111,9 +111,9 @@ fn prompt(line: &mut usize, args: &CliArgs) { fn repl_commands(command_str: &str) { let words: Vec<&str> = command_str.split(" ").map(|s| s.trim()).collect(); match words[0] { - "?help" => println!("{}", super::help::help()), - "?function" | "?functions" => println!("{}", super::help::functions()), - "?filter" | "?filters" => println!("{}", super::help::filters()), + "?help" => println!("{}", super::help::HELP_STRING), + "?function" | "?functions" => println!("{}", super::help::FUNCTIONS), + "?filter" | "?filters" => println!("{}", super::help::FILTERS), _ => println!("Unknown command, try ?help"), } }