Refactor password to string conversion to use ToString trait, add gitignore.

This commit is contained in:
ok210
2022-11-27 17:25:07 +00:00
committed by Oleksandr Kozachuk
parent a909cac999
commit 1718fb3bb1
3 changed files with 36 additions and 17 deletions
+14
View File
@@ -0,0 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
+1 -6
View File
@@ -64,12 +64,7 @@ impl<'a> LKEval<'a> {
}, },
Command::Ls => { Command::Ls => {
for (_, name) in &self.state.borrow().db { for (_, name) in &self.state.borrow().db {
let pw = name.borrow(); out.push(name.borrow().to_string());
let prefix = match pw.prefix.as_ref() { Some(s) => format!("{} ", s), None => "".to_string() };
let length = match pw.length { Some(l) => format!("{}", l), None => "".to_string() };
let comment = match pw.comment.as_ref() { Some(s) => format!(" {}", s), None => "".to_string() };
let parent = match &pw.parent { Some(s) => format!(" ^{}", s.borrow().name), None => "".to_string() };
out.push(format!("{}{} {}{} {} {}{}{}", prefix, pw.name, length, pw.mode, pw.seq, pw.date, comment, parent));
} }
}, },
Command::Add(name) => { Command::Add(name) => {
+20 -10
View File
@@ -55,18 +55,28 @@ pub struct LK {
impl std::fmt::Display for Mode { impl std::fmt::Display for Mode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { write!(f, "{}", match self {
Mode::Regular => write!(f, "R"), Mode::Regular => "R",
Mode::RegularUpcase => write!(f, "UR"), Mode::RegularUpcase => "UR",
Mode::NoSpace => write!(f, "N"), Mode::NoSpace => "N",
Mode::NoSpaceUpcase => write!(f, "UN"), Mode::NoSpaceUpcase => "UN",
Mode::Hex => write!(f, "H"), Mode::Hex => "H",
Mode::HexUpcase => write!(f, "UH"), Mode::HexUpcase => "UH",
Mode::Base64 => write!(f, "B"), Mode::Base64 => "B",
Mode::Base64Upcase => write!(f, "UB"), Mode::Base64Upcase => "UB",
Mode::Decimal => write!(f, "D"), Mode::Decimal => "D",
}.to_string())
} }
} }
impl std::string::ToString for Password {
fn to_string(&self) -> String {
let prefix = match self.prefix.as_ref() { Some(s) => format!("{} ", s), None => "".to_string() };
let length = match self.length { Some(l) => format!("{}", l), None => "".to_string() };
let comment = match self.comment.as_ref() { Some(s) => format!(" {}", s), None => "".to_string() };
let parent = match &self.parent { Some(s) => format!(" ^{}", s.borrow().name), None => "".to_string() };
format!("{}{} {}{} {} {}{}{}", prefix, self.name, length, self.mode, self.seq, self.date, comment, parent)
}
} }
impl LK { impl LK {