Refactor password to string conversion to use ToString trait, add gitignore.
This commit is contained in:
committed by
Oleksandr Kozachuk
parent
a909cac999
commit
1718fb3bb1
+14
@@ -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
@@ -64,12 +64,7 @@ impl<'a> LKEval<'a> {
|
||||
},
|
||||
Command::Ls => {
|
||||
for (_, name) in &self.state.borrow().db {
|
||||
let pw = name.borrow();
|
||||
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));
|
||||
out.push(name.borrow().to_string());
|
||||
}
|
||||
},
|
||||
Command::Add(name) => {
|
||||
|
||||
+20
-10
@@ -55,18 +55,28 @@ pub struct LK {
|
||||
|
||||
impl std::fmt::Display for Mode {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Mode::Regular => write!(f, "R"),
|
||||
Mode::RegularUpcase => write!(f, "UR"),
|
||||
Mode::NoSpace => write!(f, "N"),
|
||||
Mode::NoSpaceUpcase => write!(f, "UN"),
|
||||
Mode::Hex => write!(f, "H"),
|
||||
Mode::HexUpcase => write!(f, "UH"),
|
||||
Mode::Base64 => write!(f, "B"),
|
||||
Mode::Base64Upcase => write!(f, "UB"),
|
||||
Mode::Decimal => write!(f, "D"),
|
||||
write!(f, "{}", match self {
|
||||
Mode::Regular => "R",
|
||||
Mode::RegularUpcase => "UR",
|
||||
Mode::NoSpace => "N",
|
||||
Mode::NoSpaceUpcase => "UN",
|
||||
Mode::Hex => "H",
|
||||
Mode::HexUpcase => "UH",
|
||||
Mode::Base64 => "B",
|
||||
Mode::Base64Upcase => "UB",
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user