From 35e71b0f8a8070e19effea362cdf4ad800477f88 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sat, 16 Jan 2021 12:20:21 +0900 Subject: [PATCH] Replace string range access with strip_prefix() --- plume-macro/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 plume-macro/src/lib.rs diff --git a/plume-macro/src/lib.rs b/plume-macro/src/lib.rs old mode 100644 new mode 100755 index 7b0f5d27..deea688b --- a/plume-macro/src/lib.rs +++ b/plume-macro/src/lib.rs @@ -89,12 +89,12 @@ fn file_to_migration(file: &str) -> TokenStream2 { let mut actions = vec![]; for line in file.lines() { if sql { - if line.starts_with("--#!") { + if let Some(acc_str) = line.strip_prefix("--#!") { if !acc.trim().is_empty() { actions.push(quote!(Action::Sql(#acc))); } sql = false; - acc = line[4..].to_string(); + acc = acc_str.to_string(); acc.push('\n'); } else if line.starts_with("--") { continue; @@ -102,8 +102,8 @@ fn file_to_migration(file: &str) -> TokenStream2 { acc.push_str(line); acc.push('\n'); } - } else if line.starts_with("--#!") { - acc.push_str(&line[4..]); + } else if let Some(acc_str) = line.strip_prefix("--#!") { + acc.push_str(&acc_str); acc.push('\n'); } else if line.starts_with("--") { continue;